Dynamic Programming Interview Problems

Dynamic programming looks hard because the answer is usually short but the thinking is not. For each problem, ask three things: what is the smallest version of this question, what choices do I have at each step, and which earlier answers do I need to combine.

Start with the one-dimensional problems (climbing stairs, house robber, coin change), then move to two-dimensional grids and strings, and do knapsack and interval problems last. Write the recurrence in words before you write any code.

Coding problems

Related

Frequently asked questions

How do I know a problem needs dynamic programming?

You are asked for a count, a minimum or a maximum, and a brute-force search would repeat the same sub-problems. If a recursive solution calls itself with the same arguments more than once, memoise it.

Top-down or bottom-up?

Write the recursive version with memoisation first because it matches how you think. Convert to a table only if the interviewer asks for it or the recursion is too deep.