All problems
medium · 408 tests
Longest Substring Without Repeating Characters
Given a string s of lowercase letters, digits and spaces, print the length of the longest substring that contains no repeated character. Spaces count as characters.
Input
Line 1: t, the number of cases (1 <= t <= 1000).
Then t lines, one string s per line (1 <= |s| <= 2 * 10^5). The total length over one input is at most 10^6.
Output
For each case, one line: one integer.
Note
Read each case as a whole line; do not split on spaces. An O(n^2) solution will time out on the larger tests.
Samples
Input 1
1 abcabcbb
Output 1
3
Input 2
1 pwwkew
Output 2
3
Input 3
1 bbbbb
Output 3
1
Input 4
1 ab ba c
Output 4
4
Scoring
- Basic correctness20 pts
- Edge cases15 pts
- Random small20 pts
- Random large15 pts
- Adversarial10 pts
- Performance20 pts
2s · 256 MB