You are given an array of positive integers. Determine whether the array can be divided into two subsets such that the sum of the elements in both subsets is exactly the same.
Every element must belong to exactly one of the two subsets, and neither subset may be empty in a valid equal split (though the standard framing simply asks whether such a balanced split exists).
Return true if such a partition is possible, and false otherwise.
Example 1
Input: nums = [1,5,11,5]
Output: true
The array can be split into {1,5,5} and {11}, both summing to 11, so an equal partition exists.
Example 2
Input: nums = [1,2,3,5]
Output: false
The total is 11, which is odd, so it can never be divided into two equal integer halves.
Constraints
1 <= nums.length <= 2001 <= nums[i] <= 100The total sum is at most 200 * 100 = 2 * 10^4See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.
FDE Coach is a cohort-based program in frontend, backend, AWS, and AI where you build real products and get referred to 200+ hiring partners. The free live workshop is the fastest way to see how we teach.
750+ engineers trained · frontend, backend, AWS & AI