I'm trying to make an O(nlogn) algorithm that determines the number of pairs of values in an input array that are equal. What I was thinking of doing was storing each value of the array in another variable and continue comparing the current value to the previous values and see if there's a match and if there is then the counter goes up by one.
int current value; int previous value; for(int j = 0; j < array.length; j++){ current value = array[k] previous value = array[k-1] What I'm confused about is the fact that the running time has to be O(nlogn) so I'm wondering if that's the right kind of method to use for a problem like this or if there's a better and more convenient way of doing this.
Pseudo code:
n = array.length for k - 1 to n do if k == k-1 then increment counter by 1