Maximum number of characters between any two same character
Submissions: 946   Accuracy:

26.64%

  Difficulty: Easy   Marks: 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

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

Author: arun03


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.