hardBacktrackingPure DSA~45 min
Split Task Weights Into K Equal Loads
A scheduler must distribute indivisible task weights across exactly k identical workers so every worker carries the same total load. Decide whether such a perfectly balanced assignment exists.
Problem
Given an integer array nums and an integer k, return true if nums can be partitioned into k non-empty subsets all with equal sum.
Input
An integer array nums and an integer k.
Output
A boolean — true if a balanced k-way partition exists.
Constraints
- 1 ≤ k ≤ n ≤ 16
- 1 ≤ nums[i] ≤ 1e4
Examples
Example 1
Input
nums=[4,3,2,3,5,2,1] k=4
Output
true
Sum 20, each bucket 5: {5},{1,4},{2,3},{2,3}.
Example 2
Input
nums=[1,2,3,4] k=3
Output
false
Sum 10 is not divisible by 3.