Maximum number of characters between any two same character
Easy Accuracy: 33.54% Submissions: 1752 Points: 2

Given a string containing lower and uppercase alphabets, the task is to find the maximum number of characters between any two same character in the string.

Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow.
Each test case contains a string S.

Output:
For each test case, print the maximum number in new line. If no character repeats, print "-1".

Constraints:
1<=T<=100
1<=|string length|<=105

Example:
Input:
2
socks

FoR
Output:
3
-1

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.