Skip to main content

Dynamic Programming Pattern: LeetCode Guide & Problems

Break problems into overlapping subproblems and build up solutions bottom-up.

✓ Pattern Solutions & Guides Practice Mode Enabled
26 Problem 3 Easy 21 Medium 2 Hard

Problems (26)

Problem Solution Link
Climbing Stairs
#DP #Math #Memoization
Solution
House Robber
#Array #DP
Solution
Coin Change
#Array #DP #BFS
Solution
Longest Increasing Subsequence
#Array #DP #Binary Search
Solution
Longest Common Subsequence
#String #DP
Solution
Word Break
#String #DP #Hash Set
Solution
Edit Distance
#String #DP
Solution
Unique Paths
#Math #DP #Combinatorics
Solution
Maximum Subarray
#Array #DP #Divide and Conquer
Solution
Decode Ways
#String #DP
Solution
Min Cost Climbing Stairs
#Array #Dynamic Programming
Solution
House Robber II
#Array #Dynamic Programming
Solution
Partition Equal Subset Sum
#Array #Dynamic Programming
Solution
Target Sum
#Array #Dynamic Programming #Backtracking
Solution
Best Time to Buy and Sell Stock
#Array #Dynamic Programming
Solution
Palindromic Substrings
#String #Dynamic Programming
Solution
Longest Palindromic Substring
#String #Dynamic Programming
Solution
Best Time to Buy and Sell Stock with Cooldown
#Array #Dynamic Programming
Solution
Maximum Product Subarray
#Array #Dynamic Programming
Solution
Triangle
#Array #Dynamic Programming
Solution
Minimum Path Sum
#Array #Dynamic Programming #Matrix
Solution
Perfect Squares
#Math #Dynamic Programming #BFS
Solution
Regular Expression Matching
#String #Dynamic Programming #Recursion
Solution
Interleaving String
#String #Dynamic Programming #BFS
Solution
Best Time to Buy and Sell Stock with Transaction Fee
#Array #Dynamic Programming #Greedy
Solution
Integer Break
#Math #Dynamic Programming
Solution
🧠

Mastering the Dynamic Programming Pattern for Coding Interviews

1. Mental Model & Visual Intuition

The Dynamic Programming pattern is designed to eliminate redundant work and reduce search spaces. Rather than evaluating every possible state using a naive brute-force approach, this pattern relies on an invariant that allows you to safely discard subproblems that cannot lead to an optimal answer. When encountering an interview question, look for core triggers such as monotonicity, contiguous constraints, optimal substructure, or overlapping subproblems.

2. Algorithmic Invariants & Step-by-Step Execution

To implement this pattern flawlessly under interview conditions, structure your thought process into three discrete steps:

  • State Initialization: Define your boundaries, pointers, or memoization tables clearly before entering loops.
  • State Transition: Update tracking variables incrementally as new elements enter or leave your active evaluation window.
  • Feasibility Check: When constraints are violated, systematically shrink or adjust your state until the valid invariant is restored.

3. Time and Space Complexity Trade-Offs

In top-tier technical interviews at Google, Meta, and Amazon, arriving at a working solution is only half the battle. You must explicitly justify why your approach achieves optimal Big-O bounds. For Dynamic Programming, the target time complexity is typically Depends on state space — often O(n²) or O(n·m) while maintaining an auxiliary space complexity of O(n) with space optimization. Always discuss whether an in-place modification or two-pass traversal can save memory.

4. Common Interview Edge Cases to Test

Before informing your interviewer that you have completed coding, trace your logic against these standard high-failure test cases:

  • Empty inputs, single-element collections, or all-identical values.
  • Inputs with negative numbers, duplicates, or extreme values that could cause integer overflow.
  • Odd versus even length inputs when dealing with pointer convergence or tree midpoints.

Related Guide

A 4-Step Framework for Every DP Problem →

Dynamic programming looks hard until you realise 90% of interview DP problems follow the same four-s…

Buy me a coffee
Daily Practice
0/0