1defbiggerIsGreater(w):2# Write your code here3# traverse from right to left using i looking for a decrease using ord, if no decrease is found, return "no answer", store as ele4# if a decrease is found, find the first element greater than ele going from right, swap them5# reverse the elements from the ele to the right6 w =list(w)7 ele, index =None,None8for i inrange(len(w)-1,0,-1):9iford(w[i -1])<ord(w[i]):10 ele = w[i -1]11 index = i -112break13ifnot ele:return"no answer"1415 rightEle, rightIndex =None,None16for i inrange(len(w)-1, index,-1):17iford(w[i])>ord(ele):18 rightEle = w[i]19 rightIndex = i
20break212223 w[index], w[rightIndex]= w[rightIndex], w[index]24 res =list(w[:index +1])+list(reversed(w[index +1::]))25return"".join(res)