All Patterns

Dynamic Programming

Break problems into overlapping subproblems, cache results, and build up to the final answer.

When to use

  • Optimal substructure + overlapping subproblems
  • Counting ways
  • Min/max optimization
  • String matching

When NOT to use

  • No overlapping subproblems (use divide and conquer)
  • Greedy works and is simpler

Common traps

  • Wrong state definition
  • Wrong transition formula
  • Not initializing base cases
  • Off-by-one in table dimensions

Key Invariant

Define the state clearly, write the recurrence, then decide top-down (memo) or bottom-up (table)

Problems (42)

#14Climbing Stairs
easyFREE
#58Counting Bits
easy
#304Range Sum Query - Immutable
easy
#15Maximum Subarray
mediumFREE
#35Coin Change
mediumFREE
#36House Robber
mediumFREE
#70Longest Increasing Subsequence
medium
#71Word Break
medium
#72Unique Paths
medium
#73Min Cost Climbing Stairs
medium
#74Decode Ways
medium
#75Maximum Product Subarray
medium
#76Jump Game
medium
#1360/1 Knapsack
medium
#137Unbounded Knapsack
medium
#138Longest Common Subsequence
medium
#140Partition Equal Subset Sum
medium
#141Target Sum
medium
#142Coin Change II
medium
#144Best Time to Buy and Sell Stock with Cooldown
medium
#146Minimum Path Sum
medium
#147Paint House
medium
#148Arithmetic Slices
medium
#149Maximal Square
medium
#150Longest Palindromic Subsequence
medium
#219Longest Palindromic Substring
medium
#305Range Sum Query 2D - Immutable
medium
#307Maximum Sum Circular Subarray
medium
#100Edit Distance
hard
#101Burst Balloons
hard
#102Regular Expression Matching
hard
#103Longest Valid Parentheses
hard
#104Interleaving String
hard
#139Palindrome Partitioning II
hard
#143Distinct Subsequences
hard
#145Best Time to Buy and Sell Stock IV
hard
#284Longest Increasing Path in a Matrix
hard
#286Frog Jump
hard
#287Cherry Pickup
hard
#289Dungeon Game
hard
#290Russian Doll Envelopes
hard
#291Wildcard Matching
hard