Quota file count

Write codeEasy16 min

Your task

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.

Examples

files_needed_for_quotas(sizes: list[int], quotas: list[int]) -> list[int]
Example 1
Inputfiles_needed_for_quotas([400, 100, 250, 50], [400, 500, 800])
Output[1, 2, 4]
Example 2
Inputfiles_needed_for_quotas([120, 30], [200])
Output[-1]
Example 3
Inputfiles_needed_for_quotas([], [1])
Output[-1]