human
Find Maximum number possible by doing at | Python3 program to find maximum integer possible by doing at - most K swap operations on its digits ..
function to find maximum integer possible by doing at - most K swap operations on its digits.
return if no swaps left.
consider every digit.
and compare it with all digits after it.
if digit at position i is less than digit at position j , swap it and check for maximum number so far and recurse for remaining swaps.
swap string [ i ] with string [ j ].
If current num is more than maximum so far.
recurse of the other k - 1 swaps.
backtrack.
Driver Code"
Solution in Python:
 ... Give me a code to find Maximum number possible by doing at and the other steps required?
assistant
#Here is code to find Maximum number possible by doing at and the other steps required.
 def swap ( string , i , j ) :
	return ( string [ : i ] + string [ j ] + string [ i + 1 : j ] + string [ i ] + string [ j + 1 : ] )
def findMaximumNum ( string , k , maxm ) :
	if k == 0 :
		return
	n = len ( string )
	for i in range ( n - 1 ) :
		for j in range ( i + 1 , n ) :
			if string [ i ] < string [ j ] :
				string = swap ( string , i , j )
				if string > maxm [ 0 ] :
					maxm [ 0 ] = string
				findMaximumNum ( string , k - 1 , maxm )
				string = swap ( string , i , j )
if __name__ == " _ _ main _ _ " :
	string = "129814999"
	k = 4
	maxm = [ string ]
	findMaximumNum ( string , k , maxm )
	print ( maxm [ 0 ] )