Dynamic Programming Questions

Solving problems with overlapping subproblems and optimal substructure by memoization (top-down) and tabulation (bottom-up). Covers recognizing DP-amenable problems, defining state, transition and base cases, 1D and 2D sequence and grid formulations (knapsack and its variants, coin change, LIS, LCS, edit distance, sequence alignment, regular-expression and wildcard matching, counting-ways problems), interval DP (matrix chain, palindrome partitioning), space optimization with rolling arrays, solution reconstruction, longest paths in a DAG, game and expected-value DP, bitmask and tree DP, speeding up a DP (monotone queue, convex hull trick, divide-and-conquer optimization, bitsets, meet in the middle), and judging greedy versus DP. Ground covered elsewhere: probabilistic model inference, production caching and debugging practice, and general graph shortest-path algorithms.

MediumTechnical
69 practiced

In the 1D table for counting coin-change ways, swapping the order of the coin loop and the amount loop changes what is counted. Explain what each ordering counts and why, using a tiny example, and how this relates to shrinking the 2D coins-by-amount table to one dimension.

EasyTechnical
71 practiced

A row of houses holds nums[i] dollars each, and you cannot take from two adjacent houses. Return the maximum total you can take in O(n) time. Define the state, the transition and the base cases, and then reduce the space to O(1).

MediumTechnical
68 practiced

Extend your edit-distance solution so that it also returns one sequence of edit operations that achieves the minimum, or shows the two strings aligned. How do you recover it, and what does that do to your space optimization?

HardTechnical
91 practiced

Design an algorithm that computes a minimal list of edits (insert, delete, replace) turning one ordered JSON document into another, as a diff tool would. State your assumptions about child ordering, and analyze the time and space cost.

MediumTechnical
96 practiced

You must split an integer budget of B units among M services; spending x units on service i reduces expected loss by a known table f_i(x). Choose the split that minimizes total loss. Formulate the DP, give its complexity, and explain how you recover the allocation.

Unlock Full Question Bank

Get access to all Dynamic Programming interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.