LC 5

Longest Palindromic Substring

Medium · LC 1–100

dynamic-programmingstringtwo-pointers
Free

Candidate solution routes

Primary

Center expansion / Manacher palindrome

Free

Invariant: At loop entry s[l+1:r] is palindromic; equal new endpoints preserve symmetry.

candidate confidence: 0.612 · metadata_only

Alternate 1

Linear dynamic programming

Free

Invariant: After processing i, every state through i equals the true value under its definition, and every future transition reads only these finalized states.

candidate confidence: 0.470 · metadata_only

Alternate 2

Opposite-Direction Two Pointers

Free

Invariant: Every uneliminated pair uses endpoints inside [l,r]; a moved endpoint is proven unable to pair with any remaining opposite endpoint to satisfy the goal.

candidate confidence: 0.452 · metadata_only

Alternate 3

Same-Direction / Read-Write Pointers

Free

Invariant: After processing a[0:read], a[0:write] is exactly its correct stable filtered output, with write no farther than read+1.

candidate confidence: 0.434 · metadata_only

How to use this page

Read the statement and constraints first, then validate recognition signals, invariant, and complexity. Candidate score is not correctness evidence.