Longest Substring Without Repeating Characters
Module 11 · Sliding Window
Problem
Given a string s, return the length of the longest substring without
repeating characters.
Examples
Example 1
Input
"abcabcbb"Output3Explanation. abc
Example 2
Input
"bbbbb"Output1Explanation. b
Example 3
Input
"pwwkew"Output3Explanation. wke
Constraints
0 ≤ n ≤ 5·10⁴ · letters, digits, symbols, spaces.
Attempt it first
The dynamic-window lesson's "longest, upper-bound" template, mirrored against Minimum Size Subarray Sum's "shortest, lower-bound" shape. Validity here is "no duplicate in the window" — figure out what state answers "is the incoming character already in the window?" in O(1), and what invalidates the window when it arrives.