FastPrepMaximum Production Within Power
Problems/Maximum Production Within Power

Maximum Production Within Power

Zomato / Eternal logoZomato / Eternal● EasyFULLTIMEOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The source does not specify equal-power ordering, numeric limits, or a callable interface. The judged core task matches the visible source at about 94%.

You are given parallel integer arrays power and quantity. Machine i requires power[i] units of power and produces quantity[i] units.

Order the machines by increasing power requirement. Machines with equal power requirements keep their original input order. Starting from the beginning of this order, select machines while adding the next machine would keep cumulative power at most maxPower. Stop before the first machine that would exceed the limit.

Return the total quantity produced by the selected prefix as a 64-bit integer.

Function

maximumProduction(power: int[], quantity: int[], maxPower: long) → long

Examples

Example 1

power = [4,2,5,1]quantity = [40,20,50,10]maxPower = 7return = 70

The increasing-power order is machine indices [3,1,0,2]. The first three machines consume 1 + 2 + 4 = 7 power and produce 10 + 20 + 40 = 70 units. Adding the last machine would exceed the limit.

Example 2

power = [2,2,5]quantity = [9,100,1]maxPower = 2return = 9

The first two machines tie on power and therefore keep input order. The first machine is selected, but adding the second would make cumulative power 4, so the selected prefix produces 9 units.

Constraints

  • 1 <= power.length == quantity.length <= 200000
  • 1 <= power[i], quantity[i] <= 1000000000
  • 1 <= maxPower <= 10^18
  • The returned quantity fits in a signed 64-bit integer.

More Zomato / Eternal problems

  • Find the Two Unique NumbersONSITE INTERVIEW · Seen Oct 2026
  • Flipping MatrixONSITE INTERVIEW · Seen Oct 2026
  • Jump Game IVONSITE INTERVIEW · Seen Oct 2026
All Zomato / Eternal interview questionsSee Zomato / Eternal hiring insights
Saved
class Solution {
    public long maximumProduction(int[] power, int[] quantity, long maxPower) {
      // write your code here
    }

}
Checking account…