Sign in to run and submit your work
Reading is open to everyone. Running code and saving drafts need an account so your work is yours and comes back on your next visit.
or
CODE WORKSPACE
A backfill has to reprocess a run of daily partitions in order, oldest first, because each one depends on the state the previous one left behind. The cluster is shared, so the platform team gives the job a fixed daily quota of rows. A partition is processed whole on a single day and is never split. The team wants the smallest quota that still finishes before the deadline, so the job takes no more of the cluster than it needs.
Write min_daily_quota(partition_rows, days). It takes partition_rows, a list of non-negative integer row counts in the order the partitions must be processed, and days, an integer number of days available. It returns the smallest integer daily quota that completes every partition within days days.
Function to write
min_daily_quota(partition_rows: list[int], days: int) -> int | NoneThe smallest daily row quota that finishes every partition in order within days, 0 for no partitions, or None when days <= 0.
How to approach it
For a given quota you can count the days it needs with one greedy pass. That check only gets easier as the quota grows, so binary search the quota between the largest partition and the total.
Sample cases
+ 3 held back until you submit
a week of partitions in three days
The total is 2400, so an even share is 800, but only a quota of 900 fits the order into 3 days.
Input
Argument 1
[
300,
500,
200,
400,
100,
600,
300
]Argument 2
3Returns
900one huge partition sets the floor
Four days for four partitions, yet the quota can never go below the 900-row partition.
Input
Argument 1
[
100,
900,
100,
100
]Argument 2
4Returns
900an empty backfill
With no partitions to process, the smallest quota is 0.
Input
Argument 1
[] (empty list)
Argument 2
5Returns
0no days to do it in
Zero days means no quota can finish the work, so the answer is None.
Input
Argument 1
[
200,
300
]Argument 2
0Returns
None
Constraints
days days is allowed.days days.partition_rows returns 0: there is nothing to process.days is 0 or negative, no quota can ever finish, so return None. This check comes first, even for an empty list.Worked example
Take [300, 500, 200, 400, 100, 600, 300] with 3 days. The total is 2400 and the largest partition is 600, so the answer lies between 600 and 2400.
Check a quota of 800, the even share 2400 / 3. Day 1 takes 300 + 500 = 800; adding 200 would pass 800. Day 2 takes 200 + 400 + 100 = 700; adding 600 would pass it. Day 3 takes 600, and 300 more would make 900. Day 4 takes 300. That is 4 days, so 800 fails.
Check 900. Day 1 is 300 + 500 = 800, day 2 is 200 + 400 + 100 = 700, day 3 is 600 + 300 = 900. That is 3 days, so 900 works. At 899 the last day splits again into 600 and 300, so 4 days. The smallest quota is 900, and the binary search reaches it in eleven checks instead of trying up to 1801 quotas.
The trap is the even share. On [100, 900, 100, 100] over 4 days, 1200 / 4 = 300 cannot even hold the 900-row partition. The lower bound is the largest partition, not the total divided by the days.
What this tests
Binary search on the answer. You do not search the list, you search the range of possible quotas, because 'can quota Q finish in D days?' is monotonic: if Q works, every larger quota works too. This is LeetCode 'Capacity To Ship Packages Within D Days' in data clothing. The target is O(n log S) time and O(1) space. A linear scan over quotas passes the samples and times out when partitions hold millions of rows. Data engineers meet it when sizing a backfill's throughput, choosing a rate limit that still meets an SLA, or picking the smallest executor budget that clears a queue on time. It is not named in the data engineering interview reports we could find; it is here because it is the standard binary-search-on-the-answer problem, and a backfill quota has exactly its shape.
min_daily_quota(partition_rows: list[int], days: int) -> int | NoneSubmit for review to find out what your query gets right, what it gets wrong, and how it compares with the best working query for this exercise.
This scenario runs a full workspace — editor, canvas and results side by side. It needs a laptop or desktop to be usable. Open this page on a bigger screen to start building.