Trains the technique from
LeetCode 881Boats to Save PeopleThis 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 ski lift sends up cabins that seat at most two riders each, and a cabin may carry at most limit kilograms of rider weight in total. riders[i] is the weight in kilograms of the i-th person waiting, given in no particular order.
Everyone in the queue has to get up the mountain, and riders may be seated in any grouping you like as long as both cabin rules hold. Return the smallest number of cabins that will carry the whole queue.
No single rider ever exceeds limit, so the queue can always be cleared.
Example 1
Seating 2 with 9, 3 with 8 and 4 with 7 fills three cabins at 11 kg each, which seats all six riders inside both rules.
Example 2
One cabin takes 3 and 5 for 8 kg and the next takes 4 on its own.
Example 3
A cabin seats two riders however light they are, so the four riders fill two cabins carrying 2 kg each.
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 gondola_cabin_count(riders: list[int], limit: int) -> int:public int gondolaCabinCount(int[] riders, int limit)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.