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 Common Signal

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 Common Signal.

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

How you win

  1. 1Recognize when Longest common subsequence matches the clues
  2. 2Keep this true after every move: dp[i][j] is the LCS length of the first i and j characters
  3. 3Reach the result within O(mn) time and O(n) space

Rules and pressure

  • Target cost: O(mn) time and O(n) space
  • State rule: dp[i][j] is the LCS length of the first i and j characters
Lesson 1 of 3

Live algorithm trace

Longest common subsequence

Complete execution
1 of 5
a
first
b
c
a
c

Start with empty-prefix base states.

1dp = zeros for the second string
2for each character in first
3scan characters in second
4if equal: next = diagonal + 1
5else: next = max(top, left)
6return final state
first = abcsecond = acdp = [0,0,0]
Truth to preserve / Cost target
Truth to preserve

dp[i][j] is the LCS length of the first i and j characters

Cost target

O(mn) time and O(n) space

A state for two prefixes records their longest common subsequence length. Matching final characters extend the diagonal; a mismatch discards one side and keeps 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