Sonam Gupta and her Boyfriend
Easy Accuracy: 13.53% Submissions: 1275 Points: 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.

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.