algorythms
All Patterns
Pattern 17

Dynamic Programming

1111123413610141020i=0i=1i=2i=3

Break a problem into overlapping subproblems. Memoize results (top-down) or fill a table bottom-up. Works when the problem has optimal substructure.

Time

O(n²) or O(n·m) typically

Space

O(n) to O(n·m)

Recognize it when

  • Count ways / find min/max ways to reach a goal
  • Optimal substructure: solution built from subproblem solutions
  • "How many ways...?" or "What is the minimum cost...?"
  • Substring/subsequence problems (LCS, LIS)
Progress0/24
0 solved0 attempted

Questions — ordered by difficulty

#70Easy

Climbing Stairs

Count the number of ways to climb n stairs, taking 1 or 2 steps at a time.

dynamic-programmingmathmemoization
#198Medium

House Robber

Rob houses to maximize money without robbing two adjacent houses.

arraydynamic-programming
#416Medium

Partition Equal Subset Sum

Determine if an array can be partitioned into two subsets with equal sum.

arraydynamic-programming
#322Medium

Coin Change

Find the minimum number of coins needed to make up a given amount.

arraydynamic-programmingbfs
#1143Medium

Longest Common Subsequence

Find the length of the longest subsequence common to two strings.

stringdynamic-programming
#139Medium

Word Break

Determine if a string can be segmented into words from a dictionary.

stringdynamic-programmingtrie
#62Medium

Unique Paths

Count unique paths from top-left to bottom-right of an m×n grid (only right or down moves).

mathdynamic-programming
#72Hard

Edit Distance

Find the minimum number of operations (insert, delete, replace) to convert word1 to word2.

dynamic-programmingstring
#53Medium

Maximum Subarray

Find the contiguous subarray with the largest sum (Kadane's algorithm).

arraydynamic-programmingdivide-and-conquer
#312Hard

Burst Balloons

Burst balloons to maximize coins. Bursting balloon i gives nums[i-1]*nums[i]*nums[i+1] coins.

dynamic-programminginterval-dp
#152Medium

Maximum Product Subarray

Find the contiguous subarray with the largest product. The array may contain negative numbers and zeros.

arraydynamic-programming
#55Medium

Jump Game

Given an array where nums[i] is the maximum jump length from position i, determine if you can reach the last index.

arraygreedydynamic-programming
#115Hard

Distinct Subsequences

Count the number of distinct subsequences of string s that equal string t.

dynamic-programmingstring
#45Medium

Jump Game II

Find the minimum number of jumps to reach the last index (you are guaranteed to reach it).

arraygreedydynamic-programming
#44Hard

Wildcard Matching

Implement wildcard pattern matching with '?' (any single character) and '*' (any sequence including empty).

dynamic-programmingstringgreedy
#91Medium

Decode Ways

A string of digits can be decoded as letters (1→A, 2→B, ..., 26→Z). Count the number of ways to decode it.

stringdynamic-programming
#97Hard

Interleaving String

Check if s3 is formed by interleaving s1 and s2 while preserving their relative order.

dynamic-programmingstring
#300Medium

Longest Increasing Subsequence

Find the length of the longest strictly increasing subsequence.

dynamic-programmingbinary-search
#5Medium

Longest Palindromic Substring

Find the longest substring of s that is a palindrome.

stringdynamic-programmingtwo-pointers
#647Medium

Palindromic Substrings

Count how many substrings of s are palindromes.

stringdynamic-programmingtwo-pointers
#354Hard

Russian Doll Envelopes

Find the maximum number of envelopes you can nest (each must be strictly larger in both dimensions).

dynamic-programmingbinary-searchsorting
#10Hard

Regular Expression Matching

Implement regex matching with '.' (matches any single character) and '*' (matches zero or more of the preceding element).

stringdynamic-programmingrecursion
#518Medium

Coin Change II

Count the number of combinations of coins that make up the amount (unlimited coins of each denomination).

arraydynamic-programming
#494Medium

Target Sum

Assign + or - to each number to reach a target sum. Count the number of ways.

arraydynamic-programmingbacktracking