Back to Practice
#0279
Partition Equal Subset Sum
MediumDSA28 min20 XP
Problem
Given positive integers nums, return True if they can be partitioned into two subsets with the same sum.
Why This Matters
This is the practical subset-sum DP pattern behind many knapsack-style questions.
Function Signature
def can_partition(nums):
Examples
Example 1
Inputnums = [1,5,11,5]
OutputTrue
The subsets [11] and [1,5,5] both sum to 11.
Constraints
- Return the exact requested value.
- Handle edge cases cleanly.
- Use the intended DSA pattern when brute force would scale poorly.
CodePython
Visible browser tests run here when available.
Testcases2 visible / 3 hidden categories
Can partition
Input[1,5,11,5]
ExpectedTrue
Half the total is reachable.
Odd impossible shape
Input[1,2,3,5]
ExpectedFalse
Total is 11, so equal integer halves are impossible.
Hidden Test Categories
single numbermany small valuestarget reachable late