diff --git a/966. Vowel Spellchecker b/966. Vowel Spellchecker new file mode 100644 index 0000000..e87ac00 --- /dev/null +++ b/966. Vowel Spellchecker @@ -0,0 +1,86 @@ +class Solution { +public: + bool cons(char c) //returns true if character is a non-vowel + { + if(c!='a' && c!='e' && c!='i' && c!='o' && c!='u') + return true; + return false; + } + string modify(string s) + { + string ans=""; + for(int i=0;i<=s.size();i++) + { + if(s[i]=='a' || s[i]=='e' || s[i]=='i' || s[i]=='o' || s[i]=='u'){ + ans+="$"; + }else{ + ans+=s[i]; + } + } + return ans; + } + vector spellchecker(vector& wordlist, vector& queries) { + + int n = wordlist.size(); + + map mp_exact; + map mp_lower; + map mp_modified; + vector lower(n); + for(int i=0;i< n;i++) + { + string s = wordlist[i]; + mp_exact[s]=i+1; + + //mp_exact hashmap will store index+1 of occurence of word from wordList + + transform(s.begin(),s.end(),s.begin(),::tolower); + lower[i]=s; + if(!mp_lower[s]){ + mp_lower[s]=i+1; //we store index+1 + } + + string modified = modify(s); + if(!mp_modified[modified]){ + mp_modified[modified]=i+1; + } + + } + + int m = queries.size(); + vector ans; + for(int i=0;i only non-vowel remain + + if(mp_modified[q_mod]) + { + int ind = mp_modified[q_mod]-1; + ans.push_back(wordlist[ind]); + }else{ + ans.push_back(""); + } + } + } + } + + return ans; + + + } +};