Given an array of N elements. You have to count the minimum number of replacement require to make all the numbers in array similar. The range of every element of array is from 1 to 9 inclusive.
Count the frequency of each element of array. Lets frequencies are contained in the array freq. Find the maximum number in array freq. The answer is (N - maximum frequency).
Time complexity is O(N).
Author’s solution can be found here.