VFlash: Fast, Accurate Visual Planning via Flash Primitive Decoding
u_Unrolled
DSA for AI/ML · Module 12: Dynamic programming

Lesson 12.7 of 16 in this module Unrolled Pro

Unique Paths

Count the paths from the top-left to the bottom-right of an m × n grid moving only right or down. From enumerating every path (exponential), to the grid DP paths[r][c] = paths[r − 1][c] + paths[r][c − 1] (O(m · n)), to a single rolling row (O(n) space), to the closed form C(m + n − 2, m − 1). Then blocked cells, which break the formula but not the DP, counts modulo a prime, and the ML twin: counting the monotonic alignments between two sequences that CTC and dynamic time warping sum or optimise over.

about 10 min 4 Python examples 2 quick checks

Problem. A robot starts at the top-left cell of an m × n grid and can move only right or down. How many distinct paths reach the bottom-right cell?

text
m = 3, n = 7   →   28
m = 3, n = 2   →   3      (R D D, D R D, D D R)

Every path into cell (r, c) arrives from the cell above or the cell to its left, and those two groups are disjoint, so paths(r, c) = paths(r − 1, c) + paths(r, c − 1): lesson 12.2's recurrence on a grid.

ML context. A right-or-down path through an m × n grid is exactly a monotonic alignment between a sequence of length m and one of length n: each step either advances one sequence or the other. Dynamic time warping aligns two time series this way (lesson 12.8 minimises cost over these paths), CTC loss sums probabilities over alignments of audio frames to characters, and counting them shows why brute force over alignments is hopeless (Change D).


1. Step 1: Clarify

That's the preview. Modules 00–01 are free; this lesson is part of Unrolled Pro.
Staff AI & Pro Tier Lesson

Unlock "Unique Paths"

The foundations are free forever. Unrolled Pro unlocks the complete lesson, production architectures, and 55 battle-tested ML system design case studies.

Everything included with Pro:
All 234+ Deep-Dive Lessons across transformer internals, inference, RAG & agents
55 Staff-Level ML & System Design Case Studies with mathematical capacity estimates
AI Engineer Sheet & Exercises with worked solutions, self-checks, and code
100 Landmark Research Papers guided walkthroughs & progress tracking
14-Day Money-Back Guarantee — 100% full refund if you aren't satisfied
View Plans & Unlock All Lessons

From ₹167/mo (~$2/mo) · Cancel anytime · Instant activation

100% Risk-Free: 14-day no-questions-asked money-back guarantee