The Fibonacci sequence is defined such that each number is the sum of the two preceding ones, starting from 0 and 1.
Given n, return F(n).
This is the canonical DP warm-up: the recurrence is handed to you directly, so the only skill being tested
is whether you can trade the exponential recursion tree for a linear table.
n = 10 → 55
You are climbing a staircase with n steps. Each time you can climb 1 or 2 steps.
In how many distinct ways can you reach the top?
The recurrence ends up identical to Fibonacci, but the reasoning is different —
you arrive at step i either from step i-1 (1-step) or step i-2 (2-step),
so the number of ways is the sum of those two subproblems.
n = 5 → 8 ways
You are a robber planning to rob houses along a street. Each house has a certain amount of money.
Adjacent houses have security alarms connected — if you rob two adjacent houses, the alarm triggers.
Given an integer array nums representing the money in each house, return the
maximum amount you can rob tonight without triggering any alarm.
At each house you make a binary decision: rob it (skip the previous) or skip it (carry forward the best so far).
nums = [1, 2, 3, 1] → rob houses 0, 2: 1+3 = 4
Given two strings s1 and s2, return the length of their
longest common subsequence (LCS). A subsequence is derived from a string by deleting some
characters (possibly none) without changing the relative order of the remaining characters.
The 2D table encodes the answer to every pair of prefixes. When characters match, we extend the diagonal;
when they don't, we take the best from the row above or the column to the left.
s1 = "ace", s2 = "abcde" → LCS = "ace" → length 3
Given two words word1 and word2, return the minimum number of operations
to convert word1 into word2. You have three operations, each costing 1:
insert a character, delete a character, or replace a character.
Each cell dp[i][j] asks: "what's the cheapest way to align the first i characters of word1
with the first j characters of word2?" If the current characters match, it's free (take the diagonal);
otherwise, pay 1 and pick the cheapest of the three operations.
word1 = "intention", word2 = "execution" → 5 ops