PROBLEM 11 OF 75

Longest Substring Without Repeating Characters

Find the longest substring containing no repeated character.

PATTERNSliding windowExpand to learn; shrink to restore the rule.
SPOT THE SIGNAL

Why does this pattern fit?

FRAME · 1 OF 4

Restate the exact job

Find the longest substring containing no repeated character.

WHY THIS FITS

A duplicate invalidates only the prefix through its previous occurrence.

COMPLEXITY

O(n) time · O(k) space

COMMON FAILURE

Deleting one character instead of jumping past the prior occurrence repeats work.

THE REASONING, IN ONE PLACE

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.

Open blank recall ↗