You are viewing a single comment's thread. Return to all comments →
My Intuition based easy C++ solution:
int anagram(string s) { if(s.length()%2 != 0)return -1; unordered_map<char,int> mp1; unordered_map<char,int> mp2; int changes = 0; string s1 = s.substr(0,s.size()/2); string s2 = s.substr(s.size()/2); for(int i=0; i<s1.size();i++){ mp1[s1[i]]++; mp2[s2[i]]++; } for(auto key : mp1){ if(mp2.find(key.first) == mp2.end()){ changes += key.second; }else if(key.second > mp2[key.first]){ changes += key.second - mp2[key.first]; } } return changes; }
Seems like cookies are disabled on this browser, please enable them to open this website
Anagram
You are viewing a single comment's thread. Return to all comments →
My Intuition based easy C++ solution: