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
85 practiced
Implement wildcard pattern matching is_match(s: str, p: str) -> bool in Python supporting '?' (single char) and '*' (matches any sequence, including empty) using DP with O(n*m) time and O(n*m) space. Then discuss and implement (or describe) the greedy two-pointer approach that runs in average linear time and prove when the greedy method is correct versus when DP is necessary.
MediumTechnical
87 practiced
Implement Damerau–Levenshtein distance in Python to handle insertions, deletions, substitutions, and adjacent transpositions. Provide the DP formulation and handle edge cases (empty strings, repeated characters). Discuss runtime and where in ML this is useful (e.g., spell correction).
MediumTechnical
98 practiced
Explain the bitmask DP approach used for TSP (Held-Karp): define DP[mask][i] meaning, show the transition to extend subsets, and state time and space complexity. For n up to 20 explain practical implementation details: bit operations to iterate masks, ways to precompute distances, and common optimizations such as pruning and symmetry reductions.
MediumTechnical
73 practiced
Implement the forward algorithm for a given Hidden Markov Model to compute the probability of an observation sequence O = o1..oT. Provide Python pseudocode that computes forward probabilities α_t(s). Explain how you would modify it for numerical stability (scaling factors or log-space) and show how to obtain log-likelihood. Use a small example HMM and sequence of length 10 in your explanation.
EasyTechnical
92 practiced
You are given a computed DP table dp[i][j] storing the maximum path sum from the top-left corner to cell (i,j) in an m x n grid where moves allowed are right and down. Describe a step-by-step algorithm to reconstruct one path that achieves dp[m-1][n-1]. Explain how you handle boundaries, ties (multiple optimal paths), and adapt the approach if diagonal moves are also allowed or if obstacles (blocked cells) exist.

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.