Reported July 2026
Zomatogreedy

Robot Warehouse Optimization

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

The mistake that sinks a first attempt on Zomato's Robot Warehouse Optimization is simulating the trips one by one. Candidates reported this OA in July 2026, and with packages up to 10^9 per bay, a simulation dies instantly. The real answer is a short greedy formula with running maxima, and you can write it in six lines. Pick the base station, sum a prefix or suffix maximum, add total units, take the smaller side. If you blank on the telescoping idea during the live assessment, StealthCoder is the quiet safety net sitting invisibly on your screen. But the logic is simple enough that you should own it before you sit down.

The problem

Zomato is optimizing its automated warehouse layout. The warehouse consists of N bays arranged in a straight line, represented by a 0-indexed integer array packages, where packages[i] denotes the number of food package units stored at bay i.
The robot starts its operation at one of the two ends of the warehouse line (either at bay 0 or at bay N-1). It must choose one starting base station and use it for all operations; it cannot switch its base station halfway through.
To clear the packages, the robot performs sequential delivery trips under the following rules:
In a single trip, the robot starts at its base station, moves to a targeted bay i, picks up at most 1 unit of a package from that bay, and returns to the base station.
While traveling to a target bay i, the robot can also pick up at most 1 unit from any other intermediate bay it passes along the way for free, provided that bay still has packages left.
The travel cost of a single trip is equal to the 1-indexed distance from the robot's chosen base station to the furthest bay i it visits on that trip.If the base station is at index 0: Traveling to index i costs i + 1.
If the base station is at index N-1: Traveling to index i costs N - i.
The handling cost to load and unload a single unit of any package is always 1 unit of cost.
Your task is to return the minimum total cost (Total Travel Cost + Total Handling Cost) required to completely clear all package units from the warehouse.

Function
getMinimumCost(packages: int[]) → long

Examples
Example 1
packages = [1, 2, 3]
return = 12
Handling Cost: Total units = 1 + 2 + 3 = 6.
Strategy A (Base at index 2 - Right End):
Trip 1: Go to index 0 (distance 3). Array becomes [0, 1, 2]. Cost = 3.
Trip 2: Go to index 1 (distance 2). Array becomes [0, 0, 1]. Cost = 2.
Trip 3: Go to index 2 (distance 1). Array becomes [0, 0, 0]. Cost = 1.
Travel Cost = 3 + 2 + 1 = 6. Total = 6 + 6 = 12.
Strategy B (Base at index 0 - Left End): Requires 3 trips to the furthest element (index 2) costing 3 × 3 = 9. Total = 9 + 6 = 15.
Minimum of both is 12.
Example 2
packages = [7, 4, 7]
return = 39
Handling Cost: Total units = 7 + 4 + 7 = 18.
Travel Cost: Symmetrical array, so both ends give the same travel cost.
To clear the furthest element with 7 items, the robot must make 7 trips all the way to the other end (distance 3).
Travel Cost = 7 × 3 = 21.
Total Cost = 21 + 18 = 39.

Constraints
1 ≤ N ≤ 10^5
0 <= packages[i] < 10^9

Reported by candidates. Source: FastPrep

Pattern and pitfall

Here's the trick. Each trip grabs at most one unit per bay it passes. So for any bay j, the number of trips that must reach j is at least the max of packages[j..end], measured away from the base. Those counts are also achievable. A trip costs its furthest distance, which equals the number of bays it covers. So total travel cost is just the sum over every bay of that required trip count. For a left base, that's the sum of suffix maximums. For a right base, it's the sum of prefix maximums. Answer is the smaller sum plus total units. Check [1,2,3]: prefix maxes sum to 6, plus 6 handling gives 12. The pitfalls are int overflow (use 64-bit), forgetting handling cost, and trying to simulate. Run both directions in O(N). If the formula slips away mid-OA, StealthCoder can hand you the code as a hedge.

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 Robot Warehouse Optimization 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.

Robot Warehouse Optimization FAQ

What's the trick in Zomato's Robot Warehouse Optimization?+

Each trip takes at most one unit per bay, so bay j needs at least as many trips as the largest pile between it and the far end. Travel cost equals the sum of those running maximums. Compute it from both ends, take the smaller, then add total units.

How hard is this problem really?+

Easier than it looks. The statement is long and the simulation instinct is a trap, but the solution is one pass with a running max in each direction. The hard part is seeing the telescoping sum. Once you see it, it's about ten lines.

Why do I need a 64-bit integer?+

Values go up to 10^9 and N goes up to 10^5. A sum of running maximums can reach about 10^14, far past 32-bit range. Use long in Java, long long in C++. Python handles it natively. Overflow is the most common silent wrong-answer here.

Can I switch base stations mid-way to save cost?+

No. The statement says the robot picks one end and keeps it for all operations. So you compute the total for the left base and the right base separately, then return the minimum of the two. Don't mix them.

How do I prepare for this in 48 hours?+

Hand-verify both examples. [1,2,3] gives 12 and [7,4,7] gives 39. Then practice the pattern of turning a per-trip cost into a per-position sum using prefix or suffix maximums. Write it once from memory, test edge cases like N=1 and zeros, and you're set.

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