Dynamic Programming Mastery

DP is the single most-searched weak spot in interview prep. 60 questions covering every DP shape, from 1D sequences to advanced state-machine problems.

1D DP

2D & Grid DP

Knapsack & Subset Sum

Coin Change

medium
You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money.

Coin Change II

medium
You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money.

Combination Sum IV

medium
Given an array of distinct integers nums and a target integer target, return the number of possible combinations that add up to target.

Count the Number of Square-Free Subsets

medium
You are given a positive integer 0-indexed array nums.

Find Two Non-overlapping Sub-arrays Each With Target Sum

medium
You are given an array of integers arr and an integer target.

Inverse Coin Change

medium
You are given a 1-indexed integer array numWays, where numWays[i] represents the number of ways to select a total amount i using an infinite supply of some fixed coin denominations.

Largest Divisible Subset

medium
Given a set of distinct positive integers nums, return the largest subset answer such that every pair (answer[i], answer[j]) of elements in this subset satisfies: If there are...

Number of Dice Rolls With Target Sum

medium
You have n dice, and each dice has k faces numbered from 1 to k.

Partition Equal Subset Sum

medium
Given an integer array nums, return true if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or false otherwise.

Partition to K Equal Sum Subsets

medium
Given an integer array nums and an integer k, return true if it is possible to divide this array into k non-empty subsets whose sums are all equal.

Target Sum

medium
You are given an integer array nums and an integer target.

The Number of Beautiful Subsets

medium
You are given an array nums of positive integers and a positive integer k.

Interval & Partition DP

Advanced & State-Machine DP

Best Time to Buy and Sell Stock

easy
You are given an array prices where prices[i] is the price of a given stock on the ith day.

Best Time to Buy and Sell Stock II

medium
You are given an integer array prices where prices[i] is the price of a given stock on the ith day.

Best Time to Buy and Sell Stock V

medium
You are given an integer array prices where prices[i] is the price of a stock in dollars on the ith day, and an integer k.

Best Time to Buy and Sell Stock with Cooldown

medium
You are given an array prices where prices[i] is the price of a given stock on the ith day.

Best Time to Buy and Sell Stock with Transaction Fee

medium
You are given an array prices where prices[i] is the price of a given stock on the ith day, and an integer fee representing a transaction fee.

Count Numbers with Unique Digits

medium
Given an integer n, return the count of all numbers with unique digits, x, where 0 <= x < 10n.

Number of Smooth Descent Periods of a Stock

medium
You are given an integer array prices representing the daily price history of a stock, where prices[i] is the stock price on the ith day.

Paint House IV

medium
You are given an even integer n representing the number of houses arranged in a straight line, and a 2D array cost of size n x 3, where cost[i][j] represents the cost of painting...

Rotated Digits

medium
An integer x is a good if after rotating each digit individually by 180 degrees, we get a valid number that is different from x.

Sum of Numbers With Units Digit K

medium
Given two integers num and k, consider a set of positive integers with the following properties: Return the minimum possible size of such a set, or -1 if no such set exists.

Best Time to Buy and Sell Stock III

hard
You are given an array prices where prices[i] is the price of a given stock on the ith day.

Best Time to Buy and Sell Stock IV

hard
You are given an integer array prices where prices[i] is the price of a given stock on the ith day, and an integer k.