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 Edit Forge

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 Edit Forge.

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

How you win

  1. 1Recognize when Edit distance matches the clues
  2. 2Keep this true after every move: dp[i][j] is the minimum edits converting the first i characters to the first 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 minimum edits converting the first i characters to the first j characters
Lesson 1 of 3

Live algorithm trace

Edit distance

Complete execution
1 of 6
h
source
o
r
s
e
r

Build the empty-source row from insertion counts.

1base row costs 0 through n inserts
2for each source character
3start row with deletion cost
4if characters match: take diagonal
5else 1 + min(insert, delete, replace)
6return final distance
source = horsetarget = rosbase = [0,1,2,3]
Truth to preserve / Cost target
Truth to preserve

dp[i][j] is the minimum edits converting the first i characters to the first j characters

Cost target

O(mn) time and O(n) space

For two prefixes, equal final characters cost nothing. Otherwise insert, delete, or replace once after the cheapest neighboring prefix state.

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