human
Lexicographically largest permutation possible by a swap that is smaller than a given array | Function to lexicographic largest permutation possible by a swap that is smaller than given array.
Find the index of first element such that arr [ i ] > arr [ i + 1 ].
If the array is sorted in increasing order.
Find the index of first element which is smaller than arr [ i ].
If arr [ j ] = = arr [ j - 1 ].
Decrement j.
Swap the element.
Pr the array arr [ ].
Driver Code"
Solution in Python:

Can you provide a code to lexicographically largest permutation possible by a swap that is smaller than a given array and the other steps required?
assistant
#Here is code to lexicographically largest permutation possible by a swap that is smaller than a given array and the other steps required.
 def findPermutation ( arr ) :
	N = len ( arr )
	i = N - 2
	while ( i >= 0 and arr [ i ] <= arr [ i + 1 ] ) :
		i -= 1
	if ( i == - 1 ) :
		print ( " - 1" )
		return
	j = N - 1
	while ( j > i and arr [ j ] >= arr [ i ] ) :
		j -= 1
	while ( j > i and arr [ j ] == arr [ j - 1 ] ) :
		j -= 1
	temp = arr [ i ] ;
	arr [ i ] = arr [ j ] ;
	arr [ j ] = temp ;
	for it in arr :
		print ( it , end = " ▁ " )
arr = [ 1 , 2 , 5 , 3 , 4 , 6 ]
findPermutation ( arr )