Trains the technique from
LeetCode 2226Maximum Candies Allocated to K ChildrenThis 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 depot holds cable on reels, reels[i] being the whole number of metres left on reel i. An order calls for leads service leads, and every lead must be cut to the same whole number of metres.
A reel can be cut into as many leads as fit, and whatever is left over on it is scrap. A lead is one continuous run of cable, so it must come from a single reel: two short offcuts cannot be joined into one lead. Making more leads than the order asks for is fine, and reels may be left untouched.
Return the greatest length, in whole metres, that lets the order be filled. Return 0 when the depot cannot fill it even with one-metre leads.
Example 1
At 6 metres the reels give 2, 1 and 4 leads, which is the 7 the order asks for. At 7 metres they give only 6.
Example 2
The single reel holds 4 metres, so even one-metre leads come to 4, one short of the order.
Example 3
Each reel gives two 50-metre leads, filling the order of 4 exactly.
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 longest_lead(reels: list[int], leads: int) -> int:public int longestLead(int[] reels, long leads)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.