Uploading photos to storage
Write code · Basic · §6.3 Greedy
sizes holds the sizes (in MB) of the photos you want to upload, and capacity holds the storage space left (in MB). You may choose any of the photos, regardless of their order in sizes. A photo cannot be split, and the total size of the uploaded photos must be at most capacity.
Complete the function solution, which returns the largest number of photos you can upload.
Function
solution(sizes, capacity)
Constraints
- The length of
sizesis from 1 to 100,000. - The size of each photo is an integer from 1 to 1,000.
capacityis an integer from 0 to 100,000,000.
Examples
| sizes | capacity | result |
|---|---|---|
[4, 1, 3, 2, 9, 7] | 11 | 4 |
[200, 100, 300] | 50 | 0 |
Starter code
def solution(sizes, capacity):
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.