Trains the technique from
LeetCode 2929Distribute Candies Among Children IIThis 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 n identical parts is to be split across three bins, taken in order, and no bin may hold more than cap parts. A bin may be left empty.
Two splits count as different when some bin's count differs between them. Return how many splits there are.
Example 1
Five parts across three bins holding at most two each. The counts have to be some ordering of two, two and one, and there are three places the single part can go.
Example 2
Three parts with a cap of three means the cap never bites, so every way of writing three as an ordered triple counts: all in one bin, three ways; two and one, six ways; and one each, one way.
Example 3
Three bins of at most two hold six parts between them, which is short of ten, so no split works.
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 distribute_candies(n: int, cap: int) -> int:public long distributeCandies(int n, int cap)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.