JavaHardSliding Window35 min
Find the longest substring without repeated characters
Print the maximum length of a contiguous substring containing no repeated character. Follow the stated ordering and edge-case conventions exactly. Interviewers use this task to probe algorithm selection, invariants, and boundary handling.
Input
One line of ASCII text, possibly empty.
Output
Print the maximum length of a contiguous substring containing no repeated character.
Constraints
0 <= length <= 100000.
Example
Input
abcabcbb
Output
3
Example 2 input
a b!a
Output
4
This example exercises a further boundary or ordering case.
Public test cases (2)
Input
abcabcbb
Expected output
3
Input
bbbbb
Expected output
1
Hints (2)
- Identify the state needed to avoid recomputing work for each element.
- Maintain a sliding window and jump its left boundary past the last occurrence of a repeated character.
Target complexity: time O(n) · space O(1), ASCII alphabet
