Trains the technique from
LeetCode 1891Cutting RibbonsThis 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.
Reels of tape have the lengths reels. A reel may be cut into any number of pieces of whole-number lengths and any offcut may be thrown away, but pieces can never be joined together.
Obtain at least k pieces, all of the same whole-number length. Return the greatest length they can have, or 0 when not even a length of one can be managed.
Example 1
At a length of five each reel yields at least one piece, which is three in all. At six the reel of five yields nothing and the other two yield one apiece, leaving two pieces.
Example 2
At a length of four the reels yield one, one and two pieces, four in all. At five they yield one, one and one, which is one short.
Example 3
Even at a length of one the reels yield only twenty-one pieces between them, so no length can reach twenty-two.
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 max_length(reels: list[int], k: int) -> int:public int maxLength(int[] reels, int k)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.