Challenge
Return the length of the longest contiguous substring containing no repeated character. Characters are case-sensitive; spaces and punctuation count like letters. Return only the length.
Input and output contract
0 ≤ length ≤ 60,000. Characters are printable ASCII (codes 32–126). Empty input returns 0.
All tests follow this contract. You do not need to validate malformed input. Return the requested result from longest_unique_substring; printed output is not your answer. Standard-library tools are allowed. Implement your solution in Python 3.12.
Target complexity: O(n) expected time; O(a) auxiliary space for alphabet size a
Return values are checked by type. Use the exact function name. Print output is not your answer. Tests have time and memory limits.
Public examples
Arguments
['abba']
Expected return
2
Arguments
['abcabcbb']
Expected return
3
Arguments
['a A']
Expected return
3
Hint
Track each character’s last position. When it repeats inside your window, move the left edge forward, never backward.
The worked solution unlocks after completion, or with Premium access.