You are viewing a single comment's thread. Return to all comments →
Clean 1-liner
def equalizeArray(arr): return len(arr)-max([arr.count(i) for i in arr])
This gives 100% score but is O(n^2), and we can do better.
Better 1-liner
def equalizeArray(arr): return len(arr)-max(collections.Counter(arr).values())
Again 100%, but now O(n), using import collections
import collections
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 →
1-line Python solution
100% score, O(n)
Clean 1-liner
This gives 100% score but is O(n^2), and we can do better.
Better 1-liner
Again 100%, but now O(n), using
import collections