mediumDynamic Programming 1DPure DSA~25 min
Split Resource Costs into Two Equal Halves
A capacity planner wants to divide a set of task costs into two pools of exactly equal total cost (for balanced bin placement). Decide whether such an even split is possible.
Problem
Given an array nums of positive integers, return true if it can be partitioned into two subsets whose sums are equal, otherwise false.
Input
An array nums of positive integers.
Output
A boolean: whether an equal-sum partition exists.
Constraints
- 1 <= nums.length <= 200
- 1 <= nums[i] <= 100
Examples
Example 1
Input
nums = [1,5,11,5]
Output
true
[1,5,5] and [11] both sum to 11.
Example 2
Input
nums = [1,2,3,5]
Output
false
No subset sums to half of 11.