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.