🔥 The Mountain Looks Impossible — Until You See the Next Two Steps
🪷 The Monkey King's Puzzle of Paths
A story of steps, memory, and clarity — where a staircase becomes the first lesson in Dynamic Programming.
Characters: Monkey King, Arjun, Guru Bodhi · Arc: Beginner · Pattern: Dynamic Programming (1D)
🎭 Our Characters
- Monkey King: The Examiner — ancient, wise, poses challenges that test understanding
- Guru Bodhi: The Teacher — patient, arrives when students are lost, reveals patterns hidden in plain sight
- Arjun: The Student — eager to learn, struggles with overwhelm, discovers clarity through guidance
📜 Sutra of Dawn
Sunrise at the Gurukul. Golden light spilled across the stone steps while morning mist rose from the hillside, slow and stubborn.
At the bottom of the staircase stood Arjun. Young, eager, and already defeated.
His chest was tight. Same feeling he got before every exam, every code review. How many steps? Fifty? A hundred? He'd tried counting them last night—lying awake, staring at the ceiling—and the numbers had just... multiplied. Spiraled. How many ways to fail? his brain whispered. All of them.
High above him sat the Monkey King. Still. Staff across his lap. His tail curved up against the dawn sky like a question mark.
Tok.
One tap of the staff. Stone echoed it down the hillside.
The challenge had begun.
📜 Sutra of the Question — The Monkey King's Challenge
The Monkey King watched from above. He'd seen a thousand students stand exactly where Arjun stood—shoulders hunched, already calculating failure.
🎯 What are we calculating? How many UNIQUE WAYS are there to reach the 5th step?
Not which path is fastest, not which path is shortest — but how many different combinations exist?
Arjun's stomach dropped. Different paths? How many ways can you mix ones and twos to reach five? His mind immediately spiraled into chaos—trying to enumerate every possibility, losing track, forgetting which combinations he'd already counted.
The words died in his throat. He pressed his palm against his forehead. The combinations exploded in his head like fireworks, each one splitting into more possibilities, and more, and more—
The Monkey King's smile grew wider—not mocking, but knowing. The smile of someone who'd watched this exact moment of panic a thousand times before.
📜 Sutra of Confusion — Guru Bodhi Arrives
Footsteps. The soft whisper of robes on stone.
Guru Bodhi appeared beside him. Calm. The kind of calm that comes from watching a thousand students panic over the same problem.
He pressed his palms to his temples. "It's like—every step branches into more branches. One-one-one-two-one, two-one-one, one-two-one-one—I lose track. Forget what I've counted. Start over. Like debugging a recursive function that never hits its base case."
His hands were shaking.
Guru Bodhi didn't speak immediately. He simply stood there, patient as stone, letting Arjun's panic settle like dust after a windstorm. When he finally moved, it was slow, deliberate—resting his staff on the very first stair with the gentleness of someone placing a hand on a frightened child's shoulder.
📜 Sutra of Clarity — The Pattern Emerges
He knelt down. Traced two small marks on the first stair with the end of his staff—one mark, then another beside it. Simple. Elegant. Undeniable. The morning light caught the grooves and made them glow like answers carved in gold.
📍 Base Cases (The Foundation):
-
dp[1] = 1→ Only one way to reach step 1: take 1 step dp[2] = 2→ Two ways to reach step 2: [1+1] or [2]
Arjun stared at those marks. Then up at the stairs.
Something clicked.
The stairs hadn't changed. They were still impossibly high. But the tightness in his chest... loosened. He could breathe again.
The chaos in his head stopped spinning. Settled.
Each step wasn't some impossible mystery. It was just the sum of the two before it. That simple. Like dominoes—each one only needs the one before it to fall.
His eyes widened. "This isn't brute force. This is memory as power. This is—"
🎯 What does "Answer = 8" mean? There are 8 unique combinations to climb 5 steps.
Here are all 8 ways:
- 1 + 1 + 1 + 1 + 1 = 5 (five single steps)
- 2 + 1 + 1 + 1 = 5
- 1 + 2 + 1 + 1 = 5
- 1 + 1 + 2 + 1 = 5
- 1 + 1 + 1 + 2 = 5
- 2 + 2 + 1 = 5
- 2 + 1 + 2 = 5
- 1 + 2 + 2 = 5
📜 Real-Life Sutra — Building Anything, One Step at a Time
Arjun touched the stone step with his bare foot. Cold. Rough. Real.
"Guruji." His voice came out quieter. "This isn't just about stairs, is it?"
Pause. "This feels like... everything."
Guru Bodhi pointed his staff—not at the stairs, but at Arjun's chest. At the part of him still saying I'm not ready.
"You want to master algorithms. Get fit. Build something that matters. Every New Year you stand at step zero, stare at step 100, and give up before you even start. The gym membership. The online course. Ring any bells?"
Arjun's jaw tightened. Yes. Every single time.
"Getting fit?" Guru Bodhi continued. "You don't go from zero pushups to fifty overnight. Yesterday you did five. Last week, three. Today,
you build on yesterday.
dp[today] = dp[yesterday] + dp[two_days_ago]. Your body
remembers. It doesn't forget the pushup you did last Tuesday. It accumulates strength. But if you skip five days? The memory fades.
The staircase collapses. You're back at step 1."
"Learning to code?" The Guru's voice softened. "Yesterday you finally understood arrays. Last week, loops clicked. Today, you're staring at
linked lists and they make sense—not because you're suddenly smarter, but because you built the foundation. Step
i−1 and
i−2 are still there, holding you up."
"But when you try to skip ahead? Watch a 2x speed video on graphs and trees without understanding pointers? The staircase collapses. You
fall through the gaps. And then you blame yourself for being slow, for not 'getting it.' But the truth is simpler and kinder:
dp[trees] = dp[arrays] + dp[pointers]. You cannot skip steps.
Physics doesn't allow it. Learning doesn't allow it."
Arjun looked at the stairs again.
They hadn't shrunk. Still just as high. But they didn't feel like an impossible wall anymore.
They felt like a schedule.
A system.
A promise: Honor each step, and it'll hold you.
🧠 The Sutra of Steps — Algorithm Scroll
The Monkey King nods. Guru Bodhi traces the pattern in the air with his staff. Here's the formal description of what Arjun just discovered.
Transition
To arrive at step i, the traveler must come from:
- step i − 1 with a 1-step move, or
- step i − 2 with a 2-step move.
So we simply add those two possibilities:
dp[i] = dp[i − 1] + dp[i − 2]
Base Cases
-
dp[1] = 1
Only one way: take a single step. -
dp[2] = 2
Two ways: [1+1] or [2].
Complexity
-
Time Complexity:
O(n)
We compute each step once, from 3 to n. -
Space Complexity:
O(1)
We only store two variables (first,second), not an entire array. This is the space-optimized approach.
Guru: "Observe: we don't keep an array of all results. We only remember the last two steps. Memory is precious — use only what you need."
🔢 How the Guru Computes the Steps (Python)
Now let's see how the Guru would write this wisdom in Python — clean, efficient, and elegant.
def climb_stairs(n: int) -> int:
"""
Return the number of distinct ways to climb to step n,
where you may take 1 or 2 steps at a time.
"""
# Tiny staircases are trivial.
if n <= 2:
return n
# first = dp[1] (ways to reach step 1)
# second = dp[2] (ways to reach step 2)
first, second = 1, 2
# From step 3 onward:
# dp[i] = dp[i - 1] + dp[i - 2]
for _ in range(3, n + 1):
first, second = second, first + second
# second now holds dp[n]
return second
How this matches the sutra
-
firstalways holdsdp[i − 1]. -
secondalways holdsdp[i]. -
Each iteration slides the "window" one stair up and recomputes the new value using
dp[i] = dp[i-1] + dp[i-2].
Guru: "We remember just two numbers at a time — enough to know the past, light enough to move forward."
🔢 Bonus Example — The Fibonacci Sequence
The Monkey King tapped his staff once more, and the sound echoed like a teacher calling attention to a deeper truth.
He drew numbers in the dust:
F(0) = 0
F(1) = 1
F(2) = 0 + 1 = 1
F(3) = 1 + 1 = 2
F(4) = 1 + 2 = 3
F(5) = 2 + 3 = 5
F(6) = 3 + 5 = 8
F(7) = 5 + 8 = 13
📖 The Real Story of Fibonacci — The Rabbit Problem
This sequence comes from an 800-year-old problem posed by Leonardo Fibonacci in 1202 AD in his book Liber Abaci (The Book of Calculation).
The Rabbit Problem:
- Start with 1 pair of newborn rabbits
- Rabbits take 1 month to mature
- Each month, every mature pair produces 1 new pair
- Rabbits never die
- Question: How many pairs exist after each month?
Month 0: 1 pair (newborn)
Month 1: 1 pair (now mature, but haven't reproduced yet)
Month 2: 2 pairs (original pair + 1 new pair)
Month 3: 3 pairs (2 mature pairs reproduce → 2 + 1 = 3)
Month 4: 5 pairs (3 mature → 3 + 2 = 5)
Month 5: 8 pairs (5 mature → 5 + 3 = 8)
The Pattern: Each month's pairs = last month's pairs + two months ago (because only 2-month-old pairs reproduce).
Python Implementation:
def fibonacci(n):
# Base cases
if n == 0:
return 0
if n == 1:
return 1
# Start with F(0) and F(1)
prev, curr = 0, 1
# Build up: F(i) = F(i-1) + F(i-2)
for _ in range(2, n + 1):
prev, curr = curr, prev + curr
return curr
🔗 The Same Pattern Everywhere
Notice the pattern:
-
Climbing Stairs:
dp[i] = dp[i-1] + dp[i-2] - Fibonacci:
F(i) = F(i-1) + F(i-2)
Same formula, different contexts. One counts paths up a staircase. The other counts rabbit population. But the mathematics is identical — showing the power of recognizing patterns.
📜 Sutra of Ascent
Arjun climbed again. Different this time.
Not frantic. Just... deliberate. Each step part of a sequence he finally understood. Not because the stairs changed—he changed. His brain stopped trying to hold everything at once. Just remembered the last two steps. Trusted the pattern.
It felt less like struggling and more like recognizing something he'd always known. The stairs weren't conquered. They were understood.
At last, the final stair arrived beneath his feet. Solid. Real. Reached. The morning sun had climbed with him. The Monkey King's golden eyes gleamed with something beyond mischief now—pride, perhaps. Or recognition of a student who'd truly learned.