CoursesDynamic Programming

Grid DP

Lessons
9
Exercises
56
Minutes
62
  1. 1

    Read Up, Read Left

    DP goes 2D: each cell combines its UP and LEFT neighbors, the first row and column seed the table, and row-major fill delivers the answer to the far corner.

    Multiple choice
    6 exercises
    5 min
  2. 2

    Unique Paths

    A robot walks right/down across an m x n grid — every path's last move enters from UP or LEFT, so dp[i][j] = dp[i-1][j] + dp[i][j-1] counts them all.

    Complete codeDebugMultiple choiceTrace
    6 exercises
    6 min
  3. 3

    Unique Paths II

    Drop obstacles into the grid: a blocked cell counts 0 paths, and — the trap — edge cells AFTER an obstacle become unreachable too.

    Complete codeDebugMultiple choiceTrace
    6 exercises
    7 min
  4. 4

    Minimum Path Sum

    Minimization on the counting skeleton: dp[i][j] = grid[i][j] + min(up, left), edge rows and columns accumulate instead of counting 1s, and the corner holds the cheapest path.

    Complete codeDebugMultiple choiceTrace
    6 exercises
    7 min
  5. 5

    Triangle

    The bottom-up collapse: seed dp with the last row, fold each row upward with dp[j] = t[i][j] + min(dp[j], dp[j+1]), and the whole triangle converges to a single answer at dp[0] — no ragged-edge special cases.

    Complete codeMultiple choiceTrace
    6 exercises
    7 min
  6. 6

    Count Square Submatrices

    One cell, three witnesses: dp[i][j] = side of the largest all-ones square ending at (i,j) = min(up, left, diagonal) + 1 — and summing every dp value counts every square exactly once.

    Complete codeDebugMultiple choiceTrace
    6 exercises
    7 min
  7. 7

    Grid DP CheckpointCheckpoint

    No new concepts — carry the island's grid moves onto unseen ground: values falling with three parents, two robots whose harvests must be planned jointly, a dungeon that yields only to backward filling, and a square allowed one repaired hole.

    Complete codeMultiple choiceTrace
    6 exercises
    7 min
  8. 8

    Grid DP ReviewReview

    Mixed recap of the island: the up/left dependency shape and every fill order it permits, base edges as counts of one versus accumulated costs, obstacle zeroing and its shadow, the bottom-up collapse that tames ragged shapes, min-of-three square geometry, and the rolling row that shrinks O(mn) space to one row.

    Code orderMultiple choice
    6 exercises
    6 min
  9. 9

    Boss: Maximal SquareBoss

    The island's final test: the largest all-ones square in a binary matrix. One min-of-three recurrence certifies every square at once — and the boss's traps are trusting only two neighbors and returning the side when the problem demands the area.

    Complete codeDebugCode orderMultiple choiceTrace
    8 exercises
    10 min
AlgoFox Pro

Dynamic Programming is part of AlgoFox Pro

You can read the whole course outline here. The exercises are in the app, along with your streak, your mistake review, and the progress that carries across your devices.

Pro starts with a 3 day free trial. The app store decides who is eligible for an introductory offer, and a lapsed subscription does not get another one.

Download AlgoFox on the App StoreGet AlgoFox on Google Play

Already subscribed in the app? Sign in with the same account and Pro works here too. Quick Play and Battle are free on the web, and so is the first course in every subject.