mediumStringHash TableSliding WindowSliding Window

Longest Substring Without Repeating Characters

mediumTime: O(n)Space: O(min(n, m))

Signals to notice

longest substringno repeating charactersvariable-size window

Brute force first

Check every substring for unique characters — or. That instinct is useful because it follows the prompt literally, but it usually keeps revisiting work the problem is begging you to organize.

The key insight

Sliding window with a set: expand right, shrink left when duplicate found. The goal is not to be clever for its own sake, but to remember the one relationship that keeps the solution grounded as you move forward.

What must stay true

The window always contains unique characters — shrink left until the duplicate is removed. If that remains true after every update, the rest of the reasoning has a stable place to stand.

Easy way to go wrong

Not shrinking the window properly — remove characters from the set as you move left. The fix is usually to return to the meaning of each move, not just the steps themselves.

Sliding Window Pattern