sorting the array in descending order so as to bring values with minimal difference closer to arr [ i ]
Arrays . sort ( arr , Collections . reverseOrder ( ) ) ; for ( int i = 0 ; i < n - pairs ; i += 3 ) {