Skip to interview prep
Apexed
Problem list122 / 143

122. Set a Shared Rollout Rate

MediumBinary search

Promoting a rollout at integer rate r costs ceil(weight × r / scale) units for each service. Total cost is the sum of those units.

Return the largest rate between 0 and cap inclusive whose cost is no more than budget. Zero rate always fits.

Example 1

Input: weights = [2,3], scale = 4, cap = 10, budget = 5
Output: 4

Example 2

Input: weights = [1,1], scale = 4, cap = 7, budget = 1
Output: 0

Constraints

  • At most 10,000 weights, each in [0, 10,000].
  • 1 ≤ scale ≤ 10⁶, 0 ≤ cap ≤ 10⁶, and 0 ≤ budget ≤ 10¹⁴. All numbers are integers.

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 6 hidden and sample tests.

Code runs in an isolated browser sandbox. Progress and submissions are saved on this device.

Set a Shared Rollout Rate — coding interview practice — Apexed