InterviewStack.io LogoInterviewStack.io

Dynamic Programming Questions

Algorithmic technique for solving problems with overlapping subproblems and optimal substructure. Candidates should demonstrate identifying states and transitions, choosing memoization or bottom up tabulation, analyzing time and space complexity, reconstructing solutions from computed tables, and optimizing space or state when possible. Practice includes classic problems such as longest common subsequence, knapsack, coin change, matrix path problems, and partition problems. Interview assessment focuses on problem formulation, correctness proofs, trade offs between recursion and iterative approaches, and clear coding of the solution with edge case handling and complexity justification.

HardTechnical
123 practiced
Probabilistic DP / Expected value: You play a board game with N squares. From each square you roll a fair die to move; some squares send you forward/backward. Model this as a Markov chain and compute the expected number of turns to reach the final square from the start. Formulate the DP/linear equations E[state] = 1 + sum(p * E[next]) and implement a solver that handles N up to 1000. Discuss absorbing states and solvability.
HardTechnical
99 practiced
Knuth Optimization: Explain the Knuth optimization for DP of the form dp[i][j] = min_{i ≤ k < j} (dp[i][k] + dp[k+1][j] + w(i,j)). State sufficient conditions (quadrangle inequality and monotonicity) and show how Knuth reduces complexity from O(n^3) to O(n^2). Provide a short implementation sketch and an example application.
MediumTechnical
86 practiced
Patience-sorting LIS O(n log n) algorithm and reconstruction: Describe and implement the O(n log n) algorithm for computing the length of the Longest Increasing Subsequence (the 'tails' method). Then show how to reconstruct one LIS using predecessor pointers and binary search. Provide complexity justification and sample code sketch.
MediumTechnical
98 practiced
DP on DAG (longest path): Given a directed acyclic graph with weighted edges, compute the longest path from a source node to every other node. Implement an algorithm that uses topological order and dynamic programming to compute distances and predecessors to reconstruct paths. Explain why DP is valid in a DAG and give complexity analysis.
HardTechnical
80 practiced
Monotonic Queue / Sliding-window DP optimization: Given an array A and integers L and R (1 ≤ L ≤ R ≤ n), find the maximum subarray sum among all subarrays whose length is between L and R. Provide an O(n) algorithm using prefix sums and a monotonic queue (deque). Explain transform and amortized complexity.

Unlock Full Question Bank

Get access to hundreds of Dynamic Programming interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.