Cutting Ribbons
Find the longest length you can cut at least k equal pieces of from a set of ribbons.
The problem
Implement Solution.maxLength(ribbons, k). ribbons[i] is the length of ribbon i. You may cut each ribbon into pieces of a positive integer length and throw the leftovers away; pieces from different ribbons cannot be joined. Return the largest length x such that you can get at least k pieces that are all exactly x long, or 0 if no length works. For example, with ribbons = [9, 7, 5] and k = 3 the answer is 5: one piece from each ribbon, with 4 and 2 left over. ribbons has between 1 and 100,000 values, each from 1 to 100,000, and 1 <= k <= 1,000,000,000.
Starter code
class Solution:
def maxLength(self, ribbons, k):
passPublic examples
ribbons = [9, 7, 5], k = 3gives5ribbons = [7], k = 1gives7ribbons = [2, 3], k = 5gives1
Solving it in the practice book needs an active paid plan.
Open it in the practice bookOne thought at a time.
