First, Arrays.sort does not return the sorted array; it sorts the array in place. This means you should call Arrays.sort directly on the array without reassigning it
int[] ayush = new int[n];
ayush = Arrays.sort(heights);
// this is not possibkle as it is in place
the assignment ayush = heights makes ayush just another reference to the heights array, so sorting heights also sorts ayush. This leads to incorrect results.
int[] ayush = new int[n];
ayush = heights;
Arrays.sort(heights);
First, Arrays.sort does not return the sorted array; it sorts the array in place. This means you should call Arrays.sort directly on the array without reassigning it
the assignment ayush = heights makes ayush just another reference to the heights array, so sorting heights also sorts ayush. This leads to incorrect results.
correct way