Trains the technique from
LeetCode 1296Divide Array in Sets of K Consecutive NumbersThis 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 batch of film reels is logged as nums, where nums[i] is the length of reel i in metres. Every reel must go into a canister, and each canister must hold exactly k reels whose lengths are k consecutive whole numbers, in some order.
Return true when the batch can be split up that way, and false otherwise.
Example 1
One canister takes the reels of 4, 5 and 6 metres and the other takes 7, 8 and 9, and each holds three consecutive lengths.
Example 2
One canister must take the reels of 7, 8 and 9 metres, which leaves 7, 8 and 10, and those three are not consecutive.
Example 3
Two canisters each take reels of 2, 3 and 4 metres.
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 split_into_runs(nums: list[int], k: int) -> bool:public boolean splitIntoRuns(int[] nums, int k)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.