Code RoomQuota file count
EasyPrep Room Coding #4780

Quota file count

CodingAlgorithms & data structuresEntry–Mid~16 min

A backup service uploads a night of files to cold storage in a fixed manifest order. sizes gives each file's size in bytes in that order, and a size can be 0, because empty files happen. An operations dashboard asks the same manifest about several byte quotas at once. For each entry of quotas, return how many files, counted from the front of the manifest, have to be uploaded before the running total first reaches that quota. Return -1 for a quota the whole manifest never reaches. Every quota is at least 1. Return one answer per quota, in the order the quotas are given, and return an empty list when no quotas are asked. A manifest holds millions of files and the dashboard asks many quotas, so re-adding the sizes once per quota is too slow.

Implement
files_needed_for_quotas(sizes: list[int], quotas: list[int]) → list[int]
Examples
in[[400,100,250,50],[400,500,800]]out[1,2,4]
in[[120,30],[200]]out[-1]
in[[],[1]]out[-1]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 16 min
InputExpectedGot
[[400,100,250,50],[400,500,800]][1,2,4]not run yetsample
[[120,30],[200]][-1]not run yetsample
[[],[1]][-1]not run yetsample