You are given an integer array sources, where sources[i] is the amount of power available from the i-th power source, and an integer n representing the number of machines.
Each machine must receive power from exactly one source. A source may power multiple machines, but the total power assigned from that source cannot exceed its capacity.
Return the maximum possible value of the minimum power assigned to any machine.
Examples
01 · Example 1
sources = [5, 8, 6] n = 4 return = 4
A minimum assignment of 4 is possible: the sources can support 1 + 2 + 1 = 4 machines with at least 4 power each. A minimum of 5 would support only 1 + 1 + 1 = 3 machines.
02 · Example 2
sources = [10, 10] n = 3 return = 5
Each source can power two machines with 5 power each, so three machines can be powered. A minimum of 6 would allow only two machines total.
Constraints
1 <= sources.length1 <= nsources[i]is a non-negative integer power capacity.
More Amazon problems
- Count Promotional PeriodsOA · Seen Jun 2026
- Find Maximum Total Amount (SDE I, Fungible :)Seen Jun 2026
- Get Minimum AmountOA · Seen Jun 2026
- Find Minimum CostOA · Seen Jun 2026
- Get Smallest Base SegmentOA · Seen Jun 2026
- Maximum Non-Adjacent House ValueONSITE INTERVIEW · Seen Jun 2026
- Running Delivery Time MediansONSITE INTERVIEW · Seen Jun 2026
- Select Least Resource TasksOA · Seen Jun 2026
public int maximizeMinimumMachinePower(int[] sources, int n) {
// write your code here
}sources[5, 8, 6]
n4
expected4
sign in to submit