Partition Equal Subset Sum
Given an array of positive integers nums, decide whether it can be split into two groups whose sums are equal. Every element must go to exactly one group; the groups don't need equal sizes, only equal totals.
Return true if such a split exists, otherwise false.
Constraints: 1 <= nums.length <= 200 and 1 <= nums[i] <= 100, so the total sum is at most 20,000.
Examples
- Input:
- nums = [1, 5, 11, 5]
- Output:
- true
Split into [11] and [1, 5, 5] — both sum to 11.
- Input:
- nums = [1, 2, 3, 5]
- Output:
- false
The total is 11, an odd number, so two equal halves are impossible.
- Input:
- nums = [2, 2, 3, 5]
- Output:
- false
The total is 12, but no subset sums to 6: the closest are {2, 3} = 5 and {2, 5} = 7.
Hints
One at a time — struggle first, peek second.
Your thinking space — verify on LeetCode, then mark it.