138. Partition Equal Subset Sum
Assign every input occurrence to one of two subsets so that the two totals are equal. The subsets do not need to be contiguous or equal in size.
Each occurrence must belong to exactly one side. Equal values at different positions are separate occurrences, and empty sides follow the course's stated rules.
Example 1
Input
nums=[1,5,11,5]
Output
true
Explanation: Select the 11 occurrence; the complement 1+5+5 also totals 11.
Example 2
Input
nums=[1,2,3,5]
Output
false
Explanation: The total is odd, so equal integer totals are impossible.
Example 3
Input
nums=[1,2,5]
Output
false
Explanation: The total is eight, but no subset of distinct occurrences sums to four.
Example 4
Input
nums=[]
Output
true
Explanation: Two empty subsets both sum to zero.
Constraints
0 <= nums.length <= 2000 <= nums[i] <= 1000
Hints
Hint 1
If one side totals T, what must the complement total?
Hint 2
Use a boolean exact-sum table for processed occurrences, not reusable types.
Hint 3
Read the previous occurrence layer in place by scanning target sums downward.
Submissions
Your recent submissions for this problem.
Checking sign-in…
Discussion
Ask a question or share an approach. Posts are public; avoid personal information and mark solution spoilers clearly.
No discussion yet. Start the conversation with a question about this problem.
Checking sign-in…
Run your code to check the sample cases, or submit it to check the full validation suite.
Descending updates prevent occurrence reuse
[1,2,5]
false