Longest Substring Without Repeating Characters
Find the longest substring containing no repeated character.
Why does this pattern fit?
Restate the exact job
Find the longest substring containing no repeated character.
A duplicate invalidates only the prefix through its previous occurrence.
O(n) time · O(k) space
Deleting one character instead of jumping past the prior occurrence repeats work.
How to solve Longest Substring Without Repeating Characters
The goal is to solve this problem from the pattern, not to memorize a finished answer. Use this as a check after your own attempt.
What the question asks
Find the longest substring containing no repeated character.
Why Sliding window fits
A duplicate invalidates only the prefix through its previous occurrence.
State to maintain
A left boundary, latest index per character, and best width.
Transition
Move left past the repeated character’s latest position, never backward.
Time and space
O(n) time · O(k) space
Counterexample to the tempting mistake
Deleting one character instead of jumping past the prior occurrence repeats work.
Prove it again tomorrow
Close this page. Rebuild the state and transition from memory, write a test that exposes the mistake above, then solve a fresh input without looking back. A same-day reread is practice, not proof of retention.