PROBLEM 50 OF 75

Longest Palindromic Substring

Return the longest contiguous palindromic substring.

PATTERNDynamic programmingState is the smallest information needed to finish.
SPOT THE SIGNAL

Why does this pattern fit?

FRAME · 1 OF 4

Restate the exact job

Return the longest contiguous palindromic substring.

WHY THIS FITS

Every palindrome expands from one character or one gap.

COMPLEXITY

O(n²) time · O(1) space

COMMON FAILURE

Checking only odd centers misses even-length palindromes.

THE REASONING, IN ONE PLACE

How to solve Longest Palindromic Substring

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

Return the longest contiguous palindromic substring.

Why Dynamic programming fits

Every palindrome expands from one character or one gap.

State to maintain

Best start/length and a pair of expansion pointers.

Transition

Expand around every odd and even center, updating the longest valid range.

Time and space

O(n²) time · O(1) space

Counterexample to the tempting mistake

Checking only odd centers misses even-length palindromes.

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 ↗