We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Equalize the Array
Equalize the Array
Sort by
recency
|
1925 Discussions
|
Please Login in order to post a comment
Here is my O(N) c++ solution, you can watch the explanation here : https://youtu.be/8p9yuqSv4ek
Python solution with O(n) complexity and without using collections library:
include
using namespace std; int test(int n, vector a){ unordered_map v; for(int it : a){ v[it]++; } int max_value = 0; for(auto& pair : v){ max_value = max(max_value, pair.second); } return n - max_value; } int main(){ int n; cin >> n; vector a(n); for(int i = 0; i < n; i++){ cin >> a[i]; } cout << test(n, a) << endl; return 0; }
PHP