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 ) : NEW_LINE INDENT arr . sort ( ) NEW_LINE arr . reverse ( ) NEW_LINE DEDENT else : NEW_LINE INDENT for j in range ( n , 0 , - 1 ) : NEW_LINE INDENT if ( k > 0 ) : NEW_LINE INDENT initial_index = h [ j ] NEW_LINE best_index = n - j NEW_LINE DEDENT DEDENT DEDENT