InterviewStack.io LogoInterviewStack.io

Dynamic Programming Questions

Solving problems with overlapping subproblems and optimal substructure via memoization and tabulation. Covers recognizing DP-amenable problems, defining state and transitions, 1D/2D formulations, and space optimization. Widely regarded as the highest-difficulty and highest-discriminating coding-interview topic.

HardTechnical
79 practiced

Given a 2^n sized function f over subsets, implement Sum Over Subsets DP (SOS DP) to compute g[S] = sum_{T subset S} f[T] for all S in O(n*2^n). Provide C++ implementation and explain practical use cases in bitmask DP accelerations.

MediumTechnical
89 practiced

Given an impartial game where a player can remove 1, 3, or 4 stones on their turn from a pile of N stones, design a DP to determine which player wins with optimal play. Provide O(N) solution and explain Sprague-Grundy values and how to extend to multiple piles (Nim-sum).

MediumTechnical
73 practiced

Implement Dynamic Time Warping (DTW) distance for two time series sequences in Python. Provide O(n*m) algorithm with path reconstruction. Discuss pruning strategies (Sakoe-Chiba band) and how DTW can be used in preprocessing for time-series classification in ML pipelines.

HardTechnical
85 practiced

Explain divide-and-conquer DP optimization (a.k.a. D&C DP optimization). Given DP[k][i] = min_{j < i} (DP[k-1][j] + C[j+1..i]) where the optimal decision index is monotonic, derive how to compute a DP row in O(n log n) or O(n) and justify correctness. Provide an example DP cost function where monotonicity holds and demonstrate the algorithm.

HardTechnical
83 practiced

Describe and implement Hirschberg's algorithm for computing the Longest Common Subsequence (LCS) string using only O(min(n,m)) space. Explain how you compute forward and backward DP passes, how you split the problem at mid points, and produce the full LCS. Provide time and space complexity proofs (time O(n*m), space O(min(n,m))). Discuss practical limits for very large strings.

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.