Partition Equal Subset Sum - Problem
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.
Key Points:
- Each element can only be used once
- Both subsets must contain at least one element
- The order of elements within subsets doesn't matter
Input & Output
Example 1 — Basic Partition
$
Input:
nums = [1,5,11,5]
›
Output:
true
💡 Note:
Array can be partitioned as [1,5,5] and [11]. Both subsets have sum = 11.
Example 2 — Cannot Partition
$
Input:
nums = [1,2,3,5]
›
Output:
false
💡 Note:
Total sum = 11 (odd), so cannot be split into two equal subsets.
Example 3 — Minimum Case
$
Input:
nums = [1,1]
›
Output:
true
💡 Note:
Can partition as [1] and [1]. Both subsets have sum = 1.
Constraints
- 1 ≤ nums.length ≤ 200
- 1 ≤ nums[i] ≤ 100
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code