Skip to content

Instantly share code, notes, and snippets.

@Bahaaib
Last active July 19, 2019 05:01
Show Gist options
  • Select an option

  • Save Bahaaib/cae81b82275e93de71e15d865c6e8ff7 to your computer and use it in GitHub Desktop.

Select an option

Save Bahaaib/cae81b82275e93de71e15d865c6e8ff7 to your computer and use it in GitHub Desktop.
private static int equalizeArray(int[] arr) {
int[] index = new int[101];
int[] intrinsicIndex = new int[101];
int max = 0;
for (int i = 0; i < arr.length; i++) {
index[arr[i]]++;
}
//Select only Non-Zero integers
int position = 0;
for (int k = 0; k < index.length; k++) {
if (index[k] != 0) {
intrinsicIndex[position] = index[k];
position++;
}
}
//Find max till we reach the trailing zeros
for (int j = 0; j < intrinsicIndex.length; j++) {
if (intrinsicIndex[j] != 0) {
if (intrinsicIndex[j] > max) {
max = intrinsicIndex[j];
}
} else {
break;
}
}
return arr.length - max;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment