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

Lesson 12.2 of 16 in this module Unrolled Pro

Climbing Stairs

The number of ways to climb n stairs taking 1 or 2 steps at a time. From listing every sequence of steps (exponential), to the recurrence ways(n) = ways(n − 1) + ways(n − 2) memoised or tabulated (O(n)), to two rolling variables (O(1) space), and a 2 × 2 matrix power for astronomically large n (O(log n)). Then any set of allowed step sizes, the cheapest climb when each stair has a cost, counts modulo a prime, and the ML twin: counting how many ways a string can be split into vocabulary tokens.

about 10 min 4 Python examples 2 quick checks

Problem. You're climbing a staircase of n steps. Each move climbs 1 or 2 steps. In how many distinct ways can you reach the top?

text
n = 2   →   2      (1+1, 2)
n = 3   →   3      (1+1+1, 1+2, 2+1)
n = 5   →   8

The last move is either a 1 (from step n − 1) or a 2 (from step n − 2), and those two groups don't overlap, so ways(n) = ways(n − 1) + ways(n − 2): the Fibonacci recurrence. It's the smallest complete example of a DP: state, recurrence, base cases, order.

ML context. The same "count the ways to reach the end" DP counts how many ways a string can be segmented into vocabulary tokens (Change D), which is the denominator of a unigram tokenizer's probability model and the forward pass of segmentation lattices. Counting paths through a lattice (speech, CTC alignments) is this lesson with more edges.


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 "Climbing Stairs"

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