← Questions
Minimum hourly rate to empty every vault in time
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Uber's technical phone screen, last asked Sep 2025. It tests binary-search and greedy.
A row of vaults holds vaults[i] units each, and you have h hours. Each hour you work on one vault only and take up to k units from it; capacity left over in that hour does not carry over to another vault. Return the smallest integer rate k that empties every vault within h hours.
Interface
Unless you agree on a different interface with the interviewer, assume:
-
min_rate(vaults: list[int], h: int) -> int—0ifvaultsis empty. Otherwiseh >= len(vaults), so an answer always exists.
Example
min_rate([3, 6, 7, 11], 8) -> 4 # hours at rate 4: 1 + 2 + 2 + 3 = 8
min_rate([10], 1) -> 10
min_rate([30, 11, 23, 4, 20], 5) -> 30 # one hour per vault
min_rate([30, 11, 23, 4, 20], 6) -> 23
Constraints
-
0 <= len(vaults) <= 10^5,1 <= vaults[i] <= 10^9,len(vaults) <= h <= 10^9.
Clarifying questions
- Can a vault be split across hours? (Yes; an hour cannot be split across vaults.)
- Is
halways at least the number of vaults? - Must
kbe an integer?
What a strong answer covers
- At rate
k, vaultxtakesceil(x / k)hours; the total is non-increasing ink, so binary searchkover[1, max(vaults)]. - The check costs O(n), so the total is O(n log max(vaults)).
- Integer ceiling division without floats:
(x + k - 1) // k. - Why the upper bound is
max(vaults): at that rate each vault takes one hour. - Tests: one vault,
hequal to the number of vaults, very largeh.
Follow-ups
- Return the order of vaults and hours as a schedule.
- Each vault also has a cooldown between visits.
- Answer many queries with different
hon the same vaults.
Where it's asked
- Uber · Technical phone screen · Last asked Sep 202560 min · One medium problem with a follow-up, or two short ones; sometimes object-oriented design
What it tests
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
