You are viewing a single comment's thread. Return to all comments →
Here is my Python solution!
def biggerIsGreater(w): if "".join(sorted(list(w), reverse=True)) == w: return "no answer" i1 = len(w) - 2 while w[i1] >= w[i1 + 1]: i1 -= 1 i2 = len(w) - 1 while w[i2] <= w[i1]: i2 -= 1 left = list(w)[:i1] changed = list(w[i1:]) changed[0], changed[i2 - i1] = changed[i2 - i1], changed[0] middle = changed[0:1] right = changed[1:] right.sort() return "".join(left + middle + right)
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 →
Here is my Python solution!