Mr. Binary
Submissions: 1487   Accuracy:


  Difficulty: Easy   Marks: 2

Mr. Binary is a very greedy person. He always finds a path to do a job with minimum expense. This time his mother has asked him to go to a grocery store to buy some food items. Path to grocery store is represented by a string s containing lower case English alphabets. He can only jump to some other location j (j>i) only if s[j] = s[i]+1. He wants to find out the maximum distance he can reach, i.e., maximum index of the string he can reach.

Note: First character of the string is always 'a'. He can only go 'a'->'b','b'->'c','c'->'d' and so on. 'a'->'c','b'->'d','b'->'a' is not a valid move. He can start from any of index of 'a'. Indexing is zero based.

First line contains single integer defining the number of test cases T.Each of the next T lines contain a single string s containing only lower case english letters.

For each test case in a new line print a single integer denoting the answer for each test case.






For first test case
He can start from 'a' at index 0 or 1 or 2 and then move to 'b' at index 3 or 4, then jump to 'c' at index 5 and then go to  'd' at greater index than 6 which is 8. Thus the answer is 8.

For second test case
In second test case, again he starts from 'a' and proceed to 'b' and then 'c'. But we have 'b' at the highest index also, so he will not go to 'c' and from 'a', we will directly jump to 'b'.

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: vaibhav garg
Author: justrelax

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use, generate link and share the link here.

to report an issue on this page.