given a string W, what i want to achieve its next string lexicographically greater.
eg 1:
givenstring = "hegf"
nexthighest = "hefg"
what i have tried till now is here,
from itertools import permutations
q = int(input())
for i in range(q):
s = input()
if s == s[::-1]:
print("no answer")
else:
x = ["".join(p) for p in list(permutations(s))]
x.sort()
index = x.index(s)
print(x[index+1])
since this is not the efficient way to solve this. can u please suggest me better way to solve this problem