Equalize the Array

Problem:-Given an array of integers, determine the minimum number of elements to delete to leave only elements of equal value.

Photo by Matt Popovich on Unsplash

Solution:-
A very simple hackerrank problem where we are required to return the min number of deletions to leave only elements of equal value in the array. Let’s move towards the code, here we will require to count the occurrence of elements in arr. so we will use a list comprehension to collect the number of times the values are occurring in the “arr” and store it in list “m”. Then we will find the maximum number from the list “m” which holds the number of occurrence of each element of arr, we will be using in-built function max. Then we will return the difference between length of arr and max of m which will give the minimum number of deletion require to leave only elements of equal value.

Conclusion:-
There will be time when you will feel all alone unable to cop up with situation the only thing you can do is keep moving forward. Keep learning and keep hustling….(Cheers:-PN)

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store