In https://github.com/sangupta/ps/blob/master/solutions/2016/fa... the solution for fastest integer sorting is wrong.
/ build the boolean result array
boolean[] result = new boolean[array.length];
for(int index = 0; index < array.length; index++) {
int num = array[index];
result[num] = true;
}
The result array is the same size as the original array.But when you do:
int num = array[index];
result[num] = true;
The index being referenced in the result array is dependent on the value of num. So if num is greater than or equal to the length of the array, it throws an ArrayOutOfBoundsException. And what happens when you try sorting an array with elements having the same value?Eg- try sorting {10,5,9}
Unrelated: HN needs to allow highlighting code inline.