Skip to content

Instantly share code, notes, and snippets.

@fayimora
Created February 11, 2014 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fayimora/8945131 to your computer and use it in GitHub Desktop.
Save fayimora/8945131 to your computer and use it in GitHub Desktop.
from itertools import permutations
# s = 'abaacb'
# s = 'cbbaa'
s = raw_input()
while s != '#':
itr = iter(sorted(set(permutations(s))))
res = ()
found = False
for tup in itr:
if found:
res = tup
break
if(''.join(tup) == s):
found = True
if res is ():
print "No successor"
else:
print(''.join(res))
s = raw_input()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment