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
Understanding the Visualization
1
Input
Array of integers to partition
2
Process
Find if we can split into two equal-sum subsets
3
Output
Return true if partition possible, false otherwise
Key Takeaway
🎯 Key Insight: We only need to check if one subset with sum = total/2 exists
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code