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.

EasyTechnical
68 practiced
Write a function in Python that computes the number of unique paths in an m x n grid from top-left to bottom-right moving only right or down. Provide the DP recurrence and an implementation that handles m,n up to 1000 using combinatorics or DP with space optimization. Discuss numeric overflow and large answers.
HardTechnical
106 practiced
Implement the Cocke-Younger-Kasami (CYK) algorithm for parsing sentences using a CNF probabilistic context-free grammar (PCFG). Provide O(n^3 |G|) DP implementation, explain chart parsing, and discuss pruning, beam search, and packed representations for scaling to long sentences.
MediumTechnical
59 practiced
Describe and implement the Viterbi algorithm for HMM sequence labeling in Python. Include log-probability handling to avoid underflow and discuss smoothing/unknown observation handling in practical NLP tagging tasks.
MediumTechnical
71 practiced
Implement a digit DP in Python to count how many integers x in range [0, N] do not contain the digit '4'. Explain state design including position, tight flag, and leading-zero handling. Provide N up to 10^18 and discuss complexity.
HardTechnical
54 practiced
Advanced digit DP: count numbers in [0, N] where sum of digits modulo K equals r, for N up to 10^18 and K up to 100. Provide state design, memoization strategy, and a Python or C++ implementation. Discuss time complexity and optimizations for larger K.

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.