Skip to content
playdsa
Preferences

Make yourself comfortable.

Saved on this browser. Your device’s reduced-motion preference is always respected.

Theme
Advanced settings

The Palindrome Chamber

Learn
Play
Prove
Problem context and objectives
Mission briefing

Dungeon strategy engineer · A robot must cross a tiled dungeon

Store enough solved tile states to plan the complete route: The Palindrome Chamber.

A greedy step can trap the robot; recomputing every route is too expensive.

How you win

  1. 1Recognize when Longest palindromic subsequence matches the clues
  2. 2Keep this true after every move: dp[left][right] is the longest palindromic subsequence inside that closed interval
  3. 3Reach the result within O(n squared) time and space

Rules and pressure

  • Target cost: O(n squared) time and space
  • State rule: dp[left][right] is the longest palindromic subsequence inside that closed interval
Lesson 1 of 3

Live algorithm trace

Longest palindromic subsequence

Complete execution
1 of 6
b
left
b
b
a
b

Initialize all one-character intervals to length one.

1single characters have length 1
2grow interval lengths
3if ends match
4take inner length + 2
5else max(drop left, drop right)
6return full interval
string = bbbabdiagonal = 1
Truth to preserve / Cost target
Truth to preserve

dp[left][right] is the longest palindromic subsequence inside that closed interval

Cost target

O(n squared) time and space

An interval state asks for the best palindrome inside two boundaries. Equal ends wrap the inner answer; unequal ends discard one boundary and keep the better result.

Your call · What should guide every step of this algorithm?

Help shape PlayDSA

Something confusing, broken, or missing? Leave a quick note without leaving your lesson.

Please leave out passwords, payment details and other private information.

Page included: /

Sign in to save feedback here, or send it with your email app. Your draft stays here while you sign in.

Open email instead