Choosing the length of shorts
Write code · Medium · §8.3 Guessing the answer and checking it
videos holds the lengths (in seconds) of replay videos of live streams. You want to cut these videos into at least k short clips (shorts) that all have the same length. The length of a short is chosen in whole seconds, so it is a positive integer.
You can cut several shorts from one video, and the part left over is thrown away. You cannot join two videos to make one short. Some videos may give no shorts at all. Complete the function solution, which returns the greatest possible length of a short that still gives at least k shorts. If you cannot make k shorts even with a length of 1 second, return 0.
Function
solution(videos, k)
Constraints
- The length of
videosis from 1 to 10,000. - Each element of
videosis an integer from 1 to 100,000. kis an integer from 1 to 1,000,000,000.
Examples
| videos | k | result |
|---|---|---|
[50, 70, 35] | 4 | 35 |
[10, 10, 3] | 8 | 2 |
Starter code
def solution(videos, k):
answer = 0
return answerSolve this problem in your browser
Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.