17. Longest Substring Without Repeating Characters

Return the length of the longest substring (contiguous) of s in which no character repeats.

Example 1

Input: s = "abcabcbb"
Output: 3
Explanation: “abc” is the longest such substring.

Example 2

Input: s = "abba"
Output: 2

Constraints

  • 0 ≤ s.length ≤ 5·10⁴
Hint 1

Grow a window to the right; when a character repeats, move the left edge just past its previous position.

Sliding WindowHash TableString