Help in FOUNDATION LEVEL EXAMINATION PROBLEM:-Radesh and hashing

What to change, if the given string is the lexicographically smallest one?

MY CODE:
GOT 40% POINTS

cook your dish here

for _ in range(int(input())):
s=input()
d=0
for k in s:
d+=ord(k)-97
lol=d
f=“”
for t in range(len(s)):
if d<=25*(len(s)-t-1):
f+=“a”
else:
g=(d-(25*(len(s)-t-1)))
d-=g
f+=chr(97+g)
if f==s:
hh=1
for g in range(len(f)-1,0,-1):
if f[g]!=‘a’ and f[g-1]!=‘z’:
print(lol,f[:g-1]+chr(ord(f[g-1])+1)+chr(ord(f[g])-1)+f[g+1:])
hh=0
break
if (hh!=0):
print(-1)
else:
print(lol,f)

Search the forum - the full solution/algorithm is there already.

Thanks, turns out i dint print the hash value along with -1

1 Like