If number of swaps allowed are equal to number of elements then the resulting permutation will be descending order of given permutation .
if ( n <= k ) { arr . sort ( function ( a , b ) { return b - a ; } ) ; } else { for ( let j = n ; j >= 1 ; j -- ) { if ( k > 0 ) { let initial_index = h [ j ] ; let best_index = n - j ;