Although it printing correct value for string…i.e, printing the next lexographically larger word…
but it is not passing any test cases.
Not passing any test cases
@ashishnnnnn
your logic is correct
but you have not read question carefully
Display all the words which are in dictionary order larger than the string entered in a new line each. The output strings must be sorted.
you have to print all words but using flag you are printing only one word that is why it is no passing testcases
you just have to remove flag from condition
Modified Code
if you have more doubts regarding this feel free to ask
i hope this helps
if yes hit a like
: and don’t forgot to mark doubt as resolved 
I have done that before… Then also it was not passing any test cases.
i have checked this is code is passing all testcase
please check again