Skip to interview prep
Apexed
Problem list104 / 125

104. Longest Palindromic Subsequence

MediumDynamic programming

Return the length of the longest subsequence of s that reads the same forwards and backwards. A subsequence keeps the order of characters but may skip some.

Example 1

Input: s = "bbbab"
Output: 4
Explanation: "bbbb"

Example 2

Input: s = "cbbd"
Output: 2

Constraints

  • 0 ≤ s.length ≤ 1000

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 5 hidden and sample tests.

Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.

Longest Palindromic Subsequence — coding interview practice — Apexed