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.
Python solution with O(n) complexity and without using collections library:
defequalize_array(arr):count={}forelinarr:ifelincount:count[el]+=1else:count[el]=1# Find the maximum frequencymax_count=0forvalueincount.values():ifvalue>max_count:max_count=value# Calculate the number of elements to removereturnlen(arr)-max_count
Cookie support is required to access HackerRank
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 →
Python solution with O(n) complexity and without using collections library: