BackmediumUncategorized uncategorized medium

Minimum Threshold for Resource Allocation Solution

Problem Statement

You are given an array of positive integers `rates` of length `n`, and an integer `k`. You need to find the minimum positive integer threshold `M` such that the sum of ceil(rates[i] / M) for all 0 <= i < n is less than or equal to `k`. Here, ceil(x) represents the ceiling function, which returns the smallest integer greater than or equal to x. If no such positive integer `M` exists (which occurs when `k` is less than `n`), return -1.

Example 1
Input
rates = [3, 6, 7], k = 8
Output
undefined

Explanation: With M = 3, the sum of ceiling divisions is ceil(3/3) + ceil(6/3) + ceil(7/3) = 1 + 2 + 3 = 6, which is <= 8. For M = 2, the sum is 9, which exceeds 8.

Constraints

  • 1 <= rates.length <= 10^5
  • 1 <= rates[i] <= 10^9
  • 1 <= k <= 10^9
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free