You are viewing a single comment's thread. Return to all comments →
int migratoryBirds(vector<int> arr) { int ret = 0; unordered_map<int, int> hMap; for(int i = 0; i < arr.size(); i++) { hMap[arr[i]]++; } int key1 = -1, maxOcc1 = -1; int key2 = -1, maxOcc2 = -1; for(auto it = hMap.begin(); it != hMap.end(); it++) { if(it->second > maxOcc1) { key1 = it->first; maxOcc1 = it->second; maxOcc2 = -1; } else if(it->second == maxOcc1) { key2 = it->first; maxOcc2 = it->second; } } if(maxOcc1 == maxOcc2) { if(key1 < key2) ret = key1; else ret = key2; } else { ret = key1; } return ret; }
Seems like cookies are disabled on this browser, please enable them to open this website
Migratory Birds
You are viewing a single comment's thread. Return to all comments →