Maximum Number of Words You Can Type LeetCode solution in C++
1class Solution {2public:3int canBeTypedWords(string text, string brokenLetters) {4vector<int> ch(26, 0);5// store the broken letters6for (char c : brokenLetters) {7ch[c - 'a'] = 1;8}9// breaking text into word using string stream10stringstream s(text); // Used for breaking words11string word; // to store individual words1213int count = 0, flag = 0;14while (s >> word) {15flag = 0;16for (char &c : word) {17// if the word contains a broken letter mark flag=118if (ch[c - 'a'] == 1) {19flag = 1;20break;21}22}23// if flag is 0 which means that there is no broken letter in word so24// increase the count25if (flag == 0) count++;26}27return count;28}29};