Loading...
You are given an integer array rates, where rates[i] is the rate of the i-th worker. A worker with rate r needs r * n * n time units to complete n units of work (a lower rate means a faster worker).
You are also given an integer units, the total amount of work to complete.
All workers work at the same time, and each unit of work is completed by exactly one worker. Return the minimum number of time units needed to complete at least units units of work.
Input: rates = [4,2,3,1], units = 10
Output: 16
Explanation:
- The first worker (rate 4) completes two units in 4 * 2 * 2 = 16 time units.
- The second worker (rate 2) completes two units in 2 * 2 * 2 = 8 time units.
- The third worker (rate 3) completes two units in 3 * 2 * 2 = 12 time units.
- The fourth worker (rate 1) completes four units in 1 * 4 * 4 = 16 time units.
No assignment completes all the work in fewer than 16 time units.
Input: rates = [5,1,8], units = 6
Output: 16
Explanation:
- The first worker (rate 5) completes one unit in 5 * 1 * 1 = 5 time units.
- The second worker (rate 1) completes four units in 1 * 4 * 4 = 16 time units.
- The third worker (rate 8) completes one unit in 8 * 1 * 1 = 8 time units.
No assignment completes all the work in fewer than 16 time units.
rates.length ≤105rates[i] ≤100units ≤106Click "Run" to test with sample cases or "Submit" to run all tests.