1
// ��If you Like the repository don't foget to star & fork the repository��4
vector<int> found_Pattern(string pattern) {5
// if string is empty return empty vector.6
if (pattern.size() == 0) return {};10
// ind variable for keeping track of unique characters13
unordered_map<char, int> mp;14
for (int i = 0; i < pattern.size(); ++i) {15
// if character not present in map, insert the char with an index,16
// increment index because for next unique character the index should be18
if (mp.find(pattern[i]) == mp.end()) {19
mp.insert({pattern[i], ind++});20
// also push the index to v(numeric pattern vector)21
// mp[pattern[i]] gives the key to that character, here key is ind(which22
// we are giving to every unique character)23
v.push_back(mp[pattern[i]]);25
// if char is already in map than push index mapped to that character27
v.push_back(mp[pattern[i]]);30
// return numeric pattern33
vector<string> findAndReplacePattern(vector<string> &words, string pattern) {34
// store numeric patten of Pattern string in v35
vector<int> v = found_Pattern(pattern);40
// iterating and comparing pattern of each word with v(numeric pattern of42
for (int i = 0; i < n; ++i) {43
vector<int> pattern_word = found_Pattern(words[i]);45
// if matched add words[i] to answer vector46
if (v == pattern_word) ans.push_back(words[i]);