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 i in range(len(word)-2, -1, -1):
if word[i] < word[i+1]:
head = word[:i]
pivot = min(char for char in word[i+1:] if char > word[i])
tail = Counter(word[i:])
tail[pivot] -= 1
return head + pivot + ''.join(sorted(tail.elements()))
return '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 →
from collections import Counter
def biggerIsGreater(word):