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 Ascending Matrix

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 Ascending Matrix.

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

How you win

  1. 1Recognize when Longest increasing path matches the clues
  2. 2Keep this true after every move: memo[cell] is the exact longest increasing path beginning at that cell
  3. 3Reach the result within O(rows times cols) time and space

Rules and pressure

  • Target cost: O(rows times cols) time and space
  • State rule: memo[cell] is the exact longest increasing path beginning at that cell
Lesson 1 of 3

Live algorithm trace

Longest increasing path

Complete execution
1 of 5
9
9
4
6
6
8
2
1
cell
1

Begin DFS at value 1 with a one-cell path.

1dfs(cell) returns memo when known
2start best at 1
3for each four-direction neighbor
4if neighbor value is larger
5best = max(best, 1 + dfs(neighbor))
6memoize and return the maximum over starts
start = bottom middle 1best = 1
Truth to preserve / Cost target
Truth to preserve

memo[cell] is the exact longest increasing path beginning at that cell

Cost target

O(rows times cols) time and space

Directed moves to larger neighbors cannot form a cycle. Memoized DFS computes the best path starting at each cell once, then reuses it from every smaller neighbor.

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