Last active
July 19, 2019 05:01
-
-
Save Bahaaib/cae81b82275e93de71e15d865c6e8ff7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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