← Questions

Minimum hourly rate to empty every vault in time

0
UberCodingLast asked Sep 2025

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 — 0 if vaults is empty. Otherwise h >= 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 h always at least the number of vaults?
  • Must k be an integer?

What a strong answer covers

  • At rate k, vault x takes ceil(x / k) hours; the total is non-increasing in k, so binary search k over [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, h equal to the number of vaults, very large h.

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 h on 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

binary-search · greedy

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