Function Description
It should return the smallest lexicographically higher
string possible from the given string or no answer.
biggerIsGreater has the following parameter(s):w (a string)
Вроде бы работает корректно.
def biggerIsGreater(w):
def basic(w):
combi=list(permutations(sorted(w)))
index=combi.index(tuple(w))
return "".join(combi[index+1]) if combi[-1] != tuple(w) else 'no answer'
def res_calc(w):
new_w=w[l-9:l]
result=basic(new_w)
if result=='no answer':
result=new_w
r=w[:l - 9] + result
if r>w:
return r
else:
return biggerIsGreater(w[:l - 9])
l = len(w)
if l < 10:
return basic(w)
else:
return res_calc(w)
На hackerrank не награждают баллами, т.к. она слишком долгая по времени.