Superior Substring
Practice
3.7 (81 votes)
Algorithms
Binary search
Easy
Hash maps
Searching
Sorting
String manipulation
Problem
79% Success 21318 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code
You are given a string \(S\) of length \(N\). If a string contains at least one character whose frequency is greater than or equal to the half of the length of the string, then the string is called superior.
You are required to find the length of the longest superior substring available in the given string \(S\).
Note: Here half is considered under integer division i.e. $$9 / 2 = 4$$ , $$3 / 2 = 1$$ etc.
Input format
- First line: Integer \(T\) that represents the total number of test cases
- For each test case:
- First line: Integer \(N\) that represents the length of the string \(S\)
- Next line: String \(S\) of the length \(N\)
Output format
For each test case, print the length of the longest superior substring in a new line.
Constraints
\(1 \le T \le 10\)
\(1 \le N \le 10^5\)
The string \(S\) contains only lowercase English alphabets.
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
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
8 votes
Tags:
AlgorithmsBinary SearchDepth First SearchDisjoint setEasyGraphsLife-cycle assessmentSearching
2.Danny !
Points:30
20 votes
Tags:
Binary SearchEasySearching
Points:30
23 votes
Tags:
AlgorithmsMedium
Editorial
Login to unlock the editorial