Maximize Minimum Machine Power
Updated
Problem statement
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.
Your goal is to make the weakest machine as strong as possible. Return the most power that the machine with the least power can get.
Function
maximizeMinimumMachinePower(sources: int[], n: int) → intExamples
Example 1
sources = [5, 8, 6]n = 4return = 4Aim for at least 4 power per machine. The sources can then feed 1 + 2 + 1 = 4 machines with at least 4 power each, which is enough. Aiming for 5 would feed only 1 + 1 + 1 = 3 machines, one too few. So the answer is four.
Example 2
sources = [10, 10]n = 3return = 5With 5 power per machine, each source can feed two machines, so four machines can be powered. That is enough for all three. A minimum of 6 would let each source feed only one machine, two machines in total, which is too few. So the answer is five.
Constraints
1 <= sources.length1 <= nsources[i]is a non-negative integer power capacity.
More Amazon Onsite Interview questions
- LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Maximal SquareONSITE INTERVIEW · Seen Nov 2026
- Serialize and Deserialize a Binary TreeONSITE INTERVIEW · Seen Nov 2026
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Diagonal Traversal of a Binary TreeONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Spread Through a GridPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Optimal Account BalancingONSITE INTERVIEW · Seen Nov 2026
- Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Amazon interview experiences
- Amazon Experienced SDE Onsite Questions: 1 Experience
- Amazon SDE Onsite Interview Questions: 9 Experiences
- Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
- Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)
- Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)
- Amazon New Grad OA Problems: Every Task We Have (Part 3 of 5)