15% off all plans & roadmaps Use code
See plansLeetCode 416 · Solution & editorial
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 Equal Subset Sum is a Dynamic Programming (DP) Patterns problem, in the 1D Array (0/1 Knapsack Subset Sum Style) subpattern. The pattern covers fibonacci, Kadane, knapsack, LCS, LIS, edit distance, grid paths, and word break
Solve 0/1 knapsack, partition equal subset sum, and target sum problems.
The reference solution runs in O(n * s) time and O(s) space.
Partition Equal Subset Sum has been reported in interviews at Amazon, Facebook, Google, Microsoft.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Partition Equal Subset Sum is a Dynamic Programming (DP) Patterns problem, in the 1D Array (0/1 Knapsack Subset Sum Style) subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.