InterviewStack.io LogoInterviewStack.io

Algorithm Design and Dynamic Programming Questions

Comprehensive topic covering algorithm design with a strong emphasis on dynamic programming across beginner to advanced levels. Candidates should be able to recognize overlapping subproblems and optimal substructure, define states and derive recurrence relations, and implement correct top down memoization or bottom up tabulation. Core problem types include Fibonacci and climbing stairs for basics, coin change and basic knapsack, intermediate patterns such as longest increasing subsequence, longest common subsequence, edit distance, and matrix chain multiplication, and advanced domains including bitmask dynamic programming, dynamic programming on trees, digit dynamic programming, game theoretic dynamic programming, and multi dimensional state spaces. Evaluation includes space and time optimization techniques such as rolling arrays, state compression, reducing dimensionality, and other algorithmic optimizations including divide and conquer optimization, monotone queue optimization, and convex hull trick when applicable. Candidates are expected to refactor brute force solutions into efficient dynamic programming implementations, reason about correctness and complexity, discuss trade offs between clarity and performance, and leverage related algorithmic building blocks such as binary search, common sorting algorithms, greedy strategies, and appropriate data structures to improve solutions.

MediumTechnical
72 practiced
Implement Longest Increasing Subsequence (LIS) length in Python with O(n log n) time using patience sorting / tails array and explain how it works. Also describe how to reconstruct one LIS sequence in O(n log n) or O(n) extra memory. Discuss behavior with duplicates and strict vs non-strict LIS.
HardTechnical
56 practiced
Some DP transitions are convolution-like: dp[i] = sum_j dp[j] * w[i-j] or dp[i] = min_j dp[j] + w[i-j]. Explain when you can accelerate using FFT/NTT for sum-convolutions (polynomial multiplication) and discuss why min-plus convolution is harder. Provide algorithms and complexity trade-offs for both cases and an example application (bounded knapsack via generating functions).
HardTechnical
70 practiced
Design an algorithm for the 2D knapsack (items have weight, volume and value) with capacities W and V, using DP over two dimensions. Describe O(n * W * V) solution, memory implications, and optimization techniques: compress one dimension, sparse/dictionary DP for sparse reachable states, and Lagrangian relaxation to convert to single-dimension DP. Discuss approximation strategies when exact DP is infeasible.
MediumTechnical
50 practiced
Implement global sequence alignment (Needleman-Wunsch) in Python: given two sequences and a scoring scheme (match +1, mismatch -1, gap -1), compute the optimal alignment score and produce one optimal alignment. Explain the DP table, initialization, and backtracking procedure. Discuss affine gap penalties briefly and how they change the DP.
HardTechnical
67 practiced
Explain Sprague-Grundy theorem and design a DP to compute Grundy numbers (mex values) for impartial combinatorial games represented as a DAG of states (given adjacency lists). Provide an algorithm to compute Grundy[state] using topological order, describe complexity, and show an example.

Unlock Full Question Bank

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

Sign in to Continue

Join thousands of developers preparing for their dream job.