Browse curriculum

Dynamic Programming

Dynamic Programming Interview Questions: The Dynamic Programming Pattern

Solve each distinct subproblem once and reuse the answer. Memoization caches results on top of the natural recursion; tabulation fills a table bottom-up. Both depend on finding a recurrence that expresses a problem in terms of smaller versions of itself. Below are the dynamic programming interview questions from LeetCode, each with a step-by-step visual solution.

41

Interactive problems

2

Free to open

Recognise

How do you recognise a dynamic programming problem?

The problem asks for a count of ways, a minimum or maximum over choices, or whether something is achievable, and a brute-force recursion would solve the same subproblem repeatedly. Overlapping subproblems plus optimal substructure is the signature.

Complexity

What is the time complexity of the dynamic programming pattern?

Usually O(states × transitions). A 1D DP over n items is O(n); knapsack and most string DP are O(n × m). Space often reduces to one or two rows.

Problems

Dynamic Programming interview questions: practice problems

Each problem pairs a worked explanation with an interactive visualizer you step through yourself, plus the implementation in JavaScript, Python, Java and C++.

Complexity

Dynamic Programming problems by difficulty and complexity

The difficulty, running time and extra space of every dynamic programming solution on this page, as each lesson derives them.

LessonDifficultyBestAverageWorstSpace
Intro to Dynamic ProgrammingMediumΩ(n)Θ(n)O(n)O(n)
Solving a Question with DPMediumΩ(n)Θ(n)O(n)O(n)
Fibonacci NumberEasyΩ(1)Θ(n)O(n)O(1)
N-th Tribonacci NumberEasyΩ(1)Θ(n)O(n)O(1)
Domino and Tromino TilingMediumΩ(n)Θ(n)O(n)O(n)
Counting BitsEasyΩ(n)Θ(n)O(n)O(1)
Pascal's TriangleEasyΩ(n²)Θ(n²)O(n²)O(n²)
Min Cost Climbing StairsEasyΩ(n)Θ(n)O(n)O(n)
House RobberMediumΩ(n)Θ(n)O(n)O(n)
House Robber IIMediumΩ(n)Θ(n)O(n)O(1)
House Robber IIIMediumΩ(n)Θ(n)O(n)O(h)
Coin ChangeMediumΩ(amount · k)Θ(amount · k)O(amount · k)O(amount)
Coin Change IIMediumΩ(amount · coins)Θ(amount · coins)O(amount · coins)O(amount)
Maximum Product SubarrayMediumΩ(n)Θ(n)O(n)O(1)
Combination Sum IVMediumΩ(target · n)Θ(target · n)O(target · n)O(target)
Partition Equal Subset SumMediumΩ(n)Θ(n · sum)O(n · sum)O(sum)
Last Stone Weight IIMediumΩ(n · S)Θ(n · S)O(n · S)O(S)
Target SumMediumΩ(n)Θ(n · sum)O(n · sum)O(sum)
Decode WaysMediumΩ(n)Θ(n)O(n)O(n)
Maximal SquareMediumΩ(m · n)Θ(m · n)O(m · n)O(m · n)
Unique PathsMediumΩ(m · n)Θ(m · n)O(m · n)O(m · n)
Unique Paths IIMediumΩ(m · n)Θ(m · n)O(m · n)O(m · n)
Minimum Path SumMediumΩ(m · n)Θ(m · n)O(m · n)O(m · n)
TriangleMediumΩ(n²)Θ(n²)O(n²)O(n)
Longest Common SubsequenceMediumΩ(m · n)Θ(m · n)O(m · n)O(m · n)
Longest Palindromic SubsequenceMediumΩ(n²)Θ(n²)O(n²)O(n²)
Palindrome Partitioning IIHardΩ(n²)Θ(n²)O(n²)O(n²)
Edit DistanceMediumΩ(m · n)Θ(m · n)O(m · n)O(m · n)
Interleaving StringMediumΩ(1)Θ(m · n)O(m · n)O(m · n)
Distinct SubsequencesHardΩ(m · n)Θ(m · n)O(m · n)O(m · n)
Regular Expression MatchingHardΩ(m · n)Θ(m · n)O(m · n)O(m · n)
Wildcard MatchingHardΩ(m · n)Θ(m · n)O(m · n)O(m · n)
Burst BalloonsHardΩ(n³)Θ(n³)O(n³)O(n²)
Best Time to Buy and Sell Stock with CooldownMediumΩ(n)Θ(n)O(n)O(1)
Best Time to Buy and Sell Stock with Transaction FeeMediumΩ(n)Θ(n)O(n)O(1)
Best Time to Buy and Sell Stock IIIHardΩ(n)Θ(n)O(n)O(1)
Best Time to Buy and Sell Stock IVHardΩ(n · k)Θ(n · k)O(n · k)O(k)
Longest Increasing SubsequenceMediumΩ(n²)Θ(n²)O(n²)O(n)
Number of Longest Increasing SubsequenceMediumΩ(n²)Θ(n²)O(n²)O(n)
Word BreakMediumΩ(n)Θ(n² · k)O(n² · k)O(n + d)
Maximum Profit in Job SchedulingHardΩ(n log n)Θ(n log n)O(n log n)O(n)
Curriculum

The underlying technique is covered from first principles in the dynamic programming lesson in the DSA visualizer curriculum. Dynamic Programming is one of the 18 coding interview patterns, and its problems also appear in the DSA 75 interview sprint.

Directory

Every other coding interview pattern