Reported July 2026
Zomatosorting

Maximum Production Within Power

Reported by candidates from Zomato's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Zomato OA. Under 2s to a working solution.
Founder's read

Zomato's July 2026 OA has a problem called Maximum Production Within Power, and it looks like a knapsack until you read it twice. It isn't. You sort machines by power, keep ties in input order, and take a prefix until the next one would blow the budget. That's a sort plus a running sum. If the invite is in your inbox, this one is about clean edge handling, not cleverness. And if you blank mid-assessment, StealthCoder runs invisibly as a safety net and hands you the approach in real time.

The problem

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 = 7
return = 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 = 2
return = 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.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The whole problem reduces to: pair each power with its quantity, stable sort by power, then walk the list accumulating power and quantity. Stop at the first machine where cumulative power would exceed maxPower. Don't skip it and keep going, because the statement says stop. That's the trap. People reach for knapsack or a greedy that keeps scanning for smaller items, but sorted order means nothing later is smaller anyway. The other pitfall is overflow. maxPower goes up to 10^18 and quantities sum into 64-bit territory, so use long in Java or C++, and check total + power > maxPower before adding. Python is safe by default. Stable sorting matters for ties, though the quantity sum can differ, as Example 2 shows (9 versus 100). Sort by (power, index) to be safe. Complexity is O(n log n). If your head goes blank on the tie rule during the live OA, StealthCoder is the hedge that reads the prompt and gives you the working code.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Maximum Production Within Power cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Zomato's OA.

Zomato reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Maximum Production Within Power FAQ

How hard is Maximum Production Within Power really?+

Easy. It's a sort and a prefix walk. The difficulty is reading carefully: stable ordering on ties, stopping at the first machine that doesn't fit, and handling 64-bit sums. If you've done any sort-then-accumulate problem, you're fine.

What's the trick to this Zomato problem?+

There's no knapsack. Sort by power, ties by original index, then add machines one at a time. The moment the next one would push cumulative power over maxPower, you stop and return the quantity total. Nothing after that point gets considered.

Why do ties matter if the power is equal?+

Because the selection is a prefix, and which tied machine comes first changes what you can take. In Example 2, the first of two power-2 machines gives 9, the second would give 100. Input order decides, so use a stable sort or sort by (power, index).

What overflow traps should I watch for?+

maxPower can reach 10^18, and cumulative power and quantity sums need 64-bit integers. In Java or C++ use long. Compare with total + power > maxPower carefully, and don't use int anywhere in the accumulators. Python handles this automatically.

How do I prepare for this in 48 hours?+

Write the solution once from scratch: build index array, sort by (power, index), loop with a running sum, break on overflow of budget. Then test Example 2 and a case where the first machine alone exceeds maxPower. That's the full prep.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Zomato.

OA at Zomato?
Invisible during screen share
Get it