I have come across a problem in which my solution involves sorting an array according to some given criteria. I have an array which has some numbers and another array which just has numbers from 0 to n; arrays are of same size; and i want to sort the second array in descending order of the first array elements. To make it simple, i want to sort the first array n descending order and at the same time keep track of the indices. For ex,

int[] a = {5, 20, 10, 15}

int[] b = {0, 1, 2, 3}

If we sort ‘a’ in descending order, it would be {20, 15, 10, 5}

So, the needed array is {1, 3, 2, 0} (Sorting ‘b’ in descending order of elements of ‘a’)

I tried using Arrays.sort() but it is giving a compilation error.

Please help