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
91 practiced
You must design a DP over intervals with very large endpoints (up to 1e18) but n <= 2e5. Explain how to use coordinate compression and hashing to compress the domain, how to build DP transitions over compressed coordinates, and discuss pitfalls (off-by-one shifts, memory limits, and mapping back to original coordinates). Show how this reduces memory/time and give an example.
MediumTechnical
89 practiced
Implement the Viterbi algorithm for a Hidden Markov Model in Python: given transition matrix A, emission matrix B, initial probabilities pi, and an observation sequence O, return the most likely hidden state sequence and its log-probability. Include backpointers for reconstruction and discuss numerical stability (use of log-space). State complexity in terms of T (time steps) and S (states).
MediumTechnical
69 practiced
Given a directed acyclic graph (DAG) with weighted edges, design an algorithm to compute the longest path lengths from a source to all other nodes using DP/topological ordering. Provide pseudocode, prove correctness briefly and analyze complexity. How does this DP relate to dynamic programming used in sequence models?
MediumTechnical
99 practiced
You are given a working recursive memoized DP whose states are tuples (i,j). Explain step-by-step how to convert it into an iterative bottom-up tabulation. Explain how to determine a safe iteration order, and illustrate using the example dp[i][j] depends on dp[i-1][j] and dp[i][j-1]. Discuss pros and cons of conversion.
EasyTechnical
94 practiced
Write a Python function to compute the length of the Longest Common Subsequence (LCS) between two strings s and t using bottom-up DP. Discuss time and space complexity. Input sizes: |s|,|t| up to 2000 — what memory issues might arise and how would you mitigate them?

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.

40+ Dynamic Programming Interview Questions & Answers (2026) | InterviewStack.io