mediumDynamic Programming 1DPure DSA~30 min
Can The Workload Split Into Two Equal Halves
A batch scheduler must split a set of indivisible task weights across two identical workers so both carry the exact same total load. Decide whether such a perfectly balanced split exists.
Problem
Given an array of positive integers nums, return true if it can be partitioned into two subsets whose sums are equal, otherwise false.
Input
An integer array nums of positive values.
Output
A boolean — true if an equal-sum partition exists.
Constraints
- 1 ≤ n ≤ 200
- 1 ≤ nums[i] ≤ 100
Examples
Example 1
Input
[1,5,11,5]
Output
true
[1,5,5] and [11] both sum to 11.
Example 2
Input
[1,2,3,5]
Output
false
Total 11 is odd, so no equal split is possible.