Trains the technique from
LeetCode 698Partition to K Equal Sum SubsetsThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A rigging crew has a pile of counterweights and k identical hoists to load. nums[i] is the mass of the i-th counterweight.
Every counterweight has to end up on exactly one hoist, and each of the k hoists has to finish carrying the same total mass. A hoist may take any number of counterweights.
Return true when the pile can be dealt out that way, and false when it cannot.
Example 1
The masses total 20, so each of the four hoists must carry 5. The groupings 5, then 4 with 1, then 3 with 2, then 3 with 2 use every counterweight once and each comes to 5.
Example 2
The masses total 36, so each hoist would need 12. The only groups reaching 12 are three 4s, and there is only one such group available, so three hoists cannot all be loaded to 12.
Example 3
The masses total 4, which is not a multiple of 3, so no equal split across three hoists exists.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def can_partition_k_subsets(nums: list[int], k: int) -> bool:public boolean canPartitionKSubsets(int[] nums, int k)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.