You are viewing a single comment's thread. Return to all comments →
C++ O(n) solution:
int equalizeArray(vector<int> arr) { unordered_map<int, int> frequencies; for (int i : arr) frequencies[i]++; auto most_frequent = max_element(frequencies.begin(), frequencies.end(), [](const pair<int, int> &a, const pair<int, int> &b){ return a.second < b.second; }); return arr.size()-most_frequent->second; }
Seems like cookies are disabled on this browser, please enable them to open this website
Equalize the Array
You are viewing a single comment's thread. Return to all comments →
C++ O(n) solution: