visualization
Sliding Window
Grow greedily, shrink only when the window breaks.
s = "forgecode" · longest substring without repeating charactersstep 1/21
chars in window
empty
Empty window over "forgecode". L and R both start at index 0; the set of window chars is empty.
pseudocode
seen = set(); L = 0; best = 0for R in range(len(s)):while s[R] in seen:seen.remove(s[L]); L += 1seen.add(s[R])best = max(best, R - L + 1)return best