Sonam Gupta and her Boyfriend
Submissions: 1204   Accuracy:

12.96%

  Difficulty: Easy   Marks: 2

Sonam Gupta lives few distance far from her boyfriend which is represented in the form of String, where 1 character represents 1 unit of distance. Your task is to help her by printing the maximum distance between she and her boyfriend. Given a String s (in lowerCase only). Starting from letter 'a' which is the only source. for example:- "aaabcahd..." . Now you can only jump from one character to another in the form that a to b; b to c; c to d and so on. You have to find the maximum distance from source to her boyfriend(destination). And if there is no place to jump on then print -1.

Input:
The first line of input contains an integer denoting the no of test cases. Then T test cases follow. Each test case contains single line String input.

Output:
For each test case in a new line print the maximum distance.

Constraints:
1<=T<=100

Example:
2
aaabcb
aabac
Output:
6
5
Explanaition:
For first test case:
As 'a' will only jump to 'b' and maximum distance is 6.
For Second test case:
As 'a' will only jump to 'b' and 'b' will jump to 'c' and distance is 5.

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

Contributor: Saksham Raj Seth
Author: saksham seth


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 ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.