We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
for _ in range(int(input())):
s = input()
s = list(s[::-1])
done = 0
for i in range(1,len(s)):
if s[i-1] > s[i]:
for j in range(i):
if s[j] > s[i]:
s[j],s[i] = s[i],s[j]
s = sorted(s[:i])[::-1] + s[i:]
print("".join(s[::-1]))
break
break
else:
print("no answer")
Cookie support is required to access HackerRank
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 →
for _ in range(int(input())): s = input() s = list(s[::-1]) done = 0 for i in range(1,len(s)): if s[i-1] > s[i]: for j in range(i): if s[j] > s[i]: s[j],s[i] = s[i],s[j] s = sorted(s[:i])[::-1] + s[i:] print("".join(s[::-1])) break break else: print("no answer")