rolls[i] is the length of the i-th roll in metres. The installers need need pieces of cable of the same length, and that length must be a positive whole number of metres.
Any roll can be cut into several parts of whole lengths, or left uncut. Leftovers that are not used are thrown away; pieces cannot be joined together.
Return the greatest length for which at least need pieces can be cut. If even pieces of length 1 are not enough, return 0.rolls=[12, 7, 4], need=4 → 4
Length 4 yields 3 + 1 + 1 = 5 pieces, which is enough. Length 5 yields only 2 + 1 + 0 = 3, too few.
rolls=[3, 2], need=6 → 0
Even pieces of length 1 give only 5 in total, so the answer is 0.
rolls=[10], need=3 → 3
rolls=[12, 7, 4], need=4
4
Run checks the first 3 tests in your browser. Submit checks all 103 tests on the server, hidden ones included.