Longest Substring Without Repeating Characters

Given a printable ASCII string s, return the length of the longest contiguous substring that contains no repeated character. Spaces and symbols are ordinary…

Given a printable ASCII string `s`, return the length of the longest contiguous substring that contains no repeated character. Spaces and symbols are ordinary characters and must not be trimmed or ignored. If several longest substrings tie, only their shared length is returned; the visualizer names the earliest one as an exemplar.

- `0 <= s.length <= 5 * 10^4` - `s` contains printable ASCII letters, digits, symbols, and spaces. - The interactive visualizer accepts at most 20 characters; longer valid judge inputs are execution-only. - A substring is contiguous.

Example 1: input s = "abcabcbb"; output 3. The earliest longest substring is "abc", which has length 3. "bca" and "cab" are also valid substrings of length 3, so the answer is 3 whichever one is chosen.

Example 2: input s = "abba"; output 2. The earliest longest substring is "ab". The final a was last seen before the current window, so the left boundary must not move backward.

Example 3: input s = ""; output 0. The empty string has no characters, so its longest valid substring has length 0.

Category: Sliding Window. Topic: sliding-window. Difficulty: Medium. Patterns: sliding-window.