A crew has to share out a pile of parcels among k trucks so that every truck carries exactly the same total weight. Write can_split_equally(nums: list[int], k: int) -> bool that says whether the numbers in nums can be divided into k groups with equal sums.
- Every number goes into exactly one group; no number can be split or left out.
can_split_equally([6, 1, 5, 2, 4, 3], 3) # True (6 + 1, 5 + 2, 4 + 3: each 7)
can_split_equally([3, 3, 2, 2, 2], 2) # True (3 + 3, 2 + 2 + 2)
can_split_equally([2, 2, 2, 3], 3) # False (each group would need 3, and the 2s can't make it)
can_split_equally([9], 1) # True
Constraints: 1 <= k <= len(nums) <= 16, 1 <= nums[i] <= 10,000.
Trying every way to send each number to one of the k groups costs up to k^n, far too many when the answer is False. Aim for O(n · 2^n).
Show hint
each group must sum to total / k. Fill the groups one after another: once the open group hits that target, a new one starts. So the whole state is just which numbers are used so far; the open group's fill level follows from their sum. Don't revisit a set of used numbers you've already seen.