Solitary String
Practice
3.7 (24 votes)
Approved
Easy
String manipulation
Problem
69% Success 8819 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

In order to celebrate Women's day, Stella started playing with string S. She needs to know the maximum number of characters between any 2 same characters in the string.

As she is busy in playing, help her for the same.

If there are no 2 same characters in the string, print 1.

Note: String is composed of lowercase letters of the Latin alphabet.

Input:
First line contains one integer T, denoting the number of test cases.
Each of the next T line contains one string S.

Output:
For each test case, output the maximum number of characters between any 2 same characters in the string. If there are no 2 same characters in the string, print 1.
Print answer for each test case in a new line.

Constraints:
\(1 \le T \le 10\)
\( 1 ≤ |S| ≤ 10^5\), where S determines the length of the string.
String is composed of lowercase alphabets ranging from a to z.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
5 votes
Tags:
String AlgorithmsAlgorithmsString Searching
Points:20
13 votes
Tags:
AlgorithmsString ManipulationTwo pointer
Points:20
16 votes
Tags:
AlgorithmsString SearchingString Algorithms