You are viewing a single comment's thread. Return to all comments →
for _ in range(int(input())): s = input() has_greater = False for i in range(len(s)-1)[::-1]: if ord(s[i]) < ord(s[i+1]): for j in range(i+1,len(s))[::-1]: if ord(s[i]) < ord(s[j]): lis = list(s) lis[i],lis[j]=lis[j],lis[i] print("".join(lis[:i+1]+lis[i+1:][::-1])) has_greater = True if has_greater == True: break if has_greater == True: break if has_greater == False: print("no answer")
thanks for posting this algorithm. here's a python 3 solution based on this algorithm
Seems like cookies are disabled on this browser, please enable them to open this website
Bigger is Greater
You are viewing a single comment's thread. Return to all comments →
thanks for posting this algorithm. here's a python 3 solution based on this algorithm