dominator
I just noticed that due to copyright stuff, I can no longer copy and paste the test descriptions onto here. So kindly go here and see the test description: https://codility.com/programmers/lessons/8-leader/dominator/
Code Editor
At first I struggled a bit figuring out how I could do this in O(N) time. Turns out if I use a hashmap, I can get the stuff done quickly. The HashMap stores the key as a unique element from the input array and the value as the number of occurrences in the array. And maxOccurenceIndex is being monitored and changed as we go through the for-loop. Finally the number of occurrences stored in eachUniqNumCounter.get(A[maxOccurrenceIndex]) will be compared with A.length/2 to know if the number of occurrences is actually more than the half of the number of elements in the array. If not, it will return -1; otherwise the desired (last) index of the mode of this array.