Dynamic Programming Interview Questions 2026

DP patterns, how to recognize them in the first 3 minutes, the most frequently asked DP questions at FAANG, and the approach that turns "I don't know where to start" into systematic problem solving.

Quick Answer

Dynamic programming applies when a problem has optimal substructure and overlapping subproblems. The six core DP patterns to master: 0/1 Knapsack, Unbounded Knapsack, LCS/2D string DP, Fibonacci-style 1D DP, Interval DP, and Tree DP. Most FAANG DP questions are variants of these patterns. Recognize DP by asking: 'Does a recursive solution recompute the same subproblems?'

Why DP is High Signal

Dynamic programming appears in roughly 15% of coding interview questions based on LeakCode's database, but accounts for a disproportionate share of hiring decisions at senior levels. A correct DP solution signals mastery of problem decomposition, state definition, and optimization thinking. An incorrect DP attempt with sound reasoning often scores higher than a correct brute-force solution.

DP is also one of the most learnable interview topics. Unlike system design (which requires broad experience) or graph theory (which requires intuition), DP has recognizable patterns. Knowing 5-6 core patterns covers the majority of interview DP questions.

How to Recognize a DP Problem

A problem likely requires DP if it asks for: maximum or minimum of something, count of ways to do something, whether something is possible, or the optimal value given some constraints. The presence of overlapping subproblems is the key signal: if solving a problem requires solving the same smaller problem multiple times, memoize it.

The 3-question test: Can I solve a smaller version of this problem? Does solving larger versions require solving smaller versions repeatedly? Can I define the answer to the large problem in terms of answers to smaller problems? If all three are yes, it is a DP problem.

The Core DP Patterns

1D DP (linear)
Climbing stairs, house robber, maximum subarray, jump game, coin change
2D DP (grid)
Unique paths, minimum path sum, edit distance, longest common subsequence
Knapsack (0/1 and unbounded)
Partition equal subset sum, coin change, target sum, perfect squares
Interval DP
Burst balloons, merge stones, matrix chain multiplication
Tree DP
House robber III, diameter of binary tree, maximum path sum in tree
State machine DP
Best time to buy and sell stock (with cooldown/fee/k transactions)

Top-Down vs Bottom-Up

Top-down (memoization): write the recursive solution first, add a cache. Easier to reason about, closer to how you think about the problem. Better for interviews where explaining the recurrence relation matters.

Bottom-up (tabulation): fill a DP table starting from base cases. More space-efficient (can often reduce to O(n) space), no recursion stack overhead. Better for problems where space optimization is part of the question.

In interviews: start with top-down if you're not immediately sure of the table layout. Top-down makes the subproblem structure explicit and easier to explain. After getting to a working solution, discuss how you'd convert to bottom-up and whether you could optimize space.

Five-Step DP Process

The reliable approach to any DP problem in an interview: (1) define the state, (2) define the recurrence, (3) identify the base cases, (4) determine the iteration order, (5) optimize space if possible.

Step 1 is the discriminator: a clean state definition makes the rest easy; a sloppy state definition makes everything hard. State should be the smallest amount of information that uniquely identifies a subproblem. Common state shapes: dp[i] for sequence problems, dp[i][j] for 2D problems, dp[i][k] when there is a count constraint, dp[i][buy/sell] for state-machine problems.

Space Optimization Patterns

Many DP problems with 2D tables can be optimized to 1D. If dp[i][j] only depends on dp[i-1][...], you can keep just two rows. If dp[i][j] only depends on dp[i][j-1] and dp[i-1][j-1], you can keep one row with a single previous value.

For sequence DP (1D), often you only need the last 1-3 values, not the full array. Fibonacci can be computed in O(1) space. House robber can be O(1). LCS-style 2D can be O(min(m, n)). Interviewers at L5+ explicitly probe space optimization after you produce a working solution. Have the optimized variant ready before they ask.

When DP Is the Wrong Tool

Not every recursive problem benefits from memoization. If the state space is exponential without overlap (most subset enumeration), DP does not help. If the problem has greedy structure (interval scheduling, Dijkstra's), greedy is simpler and correct. If the problem has monotone constraints, sliding window or two pointers may be O(n) while DP is O(n^2).

Strong candidates recognize when DP is not the right reach. Reports on LeakCode tag "over-DP'd" as a real failure mode: candidates who try to apply DP to problems where a greedy or two-pointer solution exists waste round time and produce more complex code than necessary. The signal interviewers want: choose the right tool for the problem, not the most sophisticated tool you know.

Browse Real DP Questions by Company

See actual dynamic programming questions from verified FAANG and top tech company interviews.

Browse DP Questions