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

Examples

sizescapacityresult
[4, 1, 3, 2, 9, 7]114
[200, 100, 300]500

Starter code

def solution(sizes, capacity):
    answer = 0
    return answer

Solve 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.