PythonHardSliding Window35 min
Find the longest substring without repeated characters
Substrings are contiguous and characters are compared exactly. Spaces and case are significant; an empty string returns zero. Interviewers use this problem to assess use the last index of a repeated character to advance the window start.
Input
One ASCII line.
Output
Print the result on one line; print an empty line for an empty string.
Constraints
0 <= length <= 100000.
Example
Input
abcabcbb
Output
3
Example 2 input
Aa bA
Output
4
Uppercase and lowercase letters are distinct.
Public test cases (2)
Input
abcabcbb
Expected output
3
Input
pwwkew
Expected output
3
Hints (2)
- Identify the state needed to avoid repeated work.
- Use the last index of a repeated character to advance the window start.
Target complexity: time O(n) · space O(k), where k is the character alphabet size
