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.
thats precisely my point. i solved it using an array on 100 positions as the input is only going to be in the range of 1 <= x <= 100....
...this is an classic Counting Sort problem...
static int EqualizeArray(int[] arr)
{
int max = 0;
int[] d = new int[101];
for (int i = 0; i < arr.Length; i++)
{
d[arr[i]]++;
if (d[arr[i]] > max)
max = d[arr[i]];
}
return arr.Length - max;
}
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 →
thats precisely my point. i solved it using an array on 100 positions as the input is only going to be in the range of 1 <= x <= 100.... ...this is an classic Counting Sort problem... static int EqualizeArray(int[] arr) { int max = 0; int[] d = new int[101]; for (int i = 0; i < arr.Length; i++) { d[arr[i]]++; if (d[arr[i]] > max) max = d[arr[i]]; }