human
How to find Lexicographically previous permutation ? | Function to compute the previous permutation.
Find index of the last element of the string.
Find largest index i such that str [ i - 1 ] > str [ i ].
if string is sorted in ascending order we 're at the last permutation.
Note - str [ i . . n ] is sorted in ascending order . Find rightmost element 's index  that is less than str[i - 1].
Swap character at i - 1 with j.
Reverse the substring [ i . . n ].
Driver code"
Solution in Python:
 ... Can you provide a code to how to find Lexicographically previous permutation?
assistant
#Here is code to how to find Lexicographically previous permutation .
 def prevPermutation ( str ) :
	n = len ( str ) - 1
	i = n
	while ( i > 0 and str [ i - 1 ] <= str [ i ] ) :
		i -= 1
	if ( i <= 0 ) :
		return False
	j = i - 1
	while ( j + 1 <= n and str [ j + 1 ] <= str [ i - 1 ] ) :
		j += 1
	str = list ( str )
	temp = str [ i - 1 ]
	str [ i - 1 ] = str [ j ]
	str [ j ] = temp
	str = ' ' . join ( str )
	str [ : : - 1 ]
	return True , str
if __name__ == ' _ _ main _ _ ' :
	str = "4321"
	b , str = prevPermutation ( str )
	if ( b == True ) :
		print ( " Previous ▁ permutation ▁ is " , str )
	else :
		print ( " Previous ▁ permutation ▁ doesn ' t ▁ exist " )