Robot Inventory Tracking
Reported by candidates from Airbnb's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Airbnb reportedly asked this one in July 2026, and the detail that trips people is the upgrade record. Supply and sell are easy. Then a log line moves units from one price to a higher price, and your cheapest-first rule has to survive it. This is a hash table problem wearing a simulation costume: per robot, keep a price-to-count map and process the logs in order. If you blank on the structure the night of the OA, StealthCoder runs invisibly as a safety net while you work through it.
The problem
Implement an inventory tracking system for a robot retail store. You are given a transaction log logs. Process every record in order. Each record has one of these formats: ["supply", robotName, count, price]: add count units of robotName to inventory at unit price price. ["sell", robotName, count]: sell count units of robotName. If units are available at different prices, sell the cheapest units first. ["upgrade", robotName, count, oldPrice, newPrice]: move count units of robotName from oldPrice to the higher price newPrice. The count and price fields are decimal strings. Return an integer array containing the revenue from each sell transaction in the order those transactions appear. A solution with time complexity no worse than O(logs.length^2) fits within the execution time limit. Function trackRobotInventory(logs: String[][]) → int[] Examples Example 1 logs = [["supply","robot1","2","100"],["supply","robot2","3","60"],["sell","robot1","1"],["sell","robot2","1"],["upgrade","robot2","1","60","100"],["sell","robot2","1"],["sell","robot2","1"]] return = [100,60,60,100] The two supply records add two robot1 units at price 100 and three robot2 units at price 60. Selling one robot1 produces revenue 100. Selling one robot2 produces revenue 60. The upgrade record moves one remaining robot2 unit from price 60 to price 100. The next robot2 sale uses the remaining price-60 unit first, producing revenue 60. The final robot2 sale uses the price-100 unit, producing revenue 100. The revenues are therefore [100,60,60,100]. Constraints Every sell transaction can be fulfilled by the current inventory. Every upgrade transaction has at least count matching units at oldPrice. For every upgrade transaction, newPrice is higher than oldPrice.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Keep a map from robotName to another map of price to count. Supply adds count at that price. Upgrade subtracts count from oldPrice (delete the key at zero) and adds it to newPrice. Sell sorts that robot's prices ascending, takes from the cheapest bucket first, and sums price times units taken. Parse the count and price strings to integers first. The stated bound is O(n^2), so sorting the price keys on every sell is fine and a heap or tree map is overkill. Common pitfalls: forgetting to merge into an existing newPrice bucket, leaving zero-count buckets that corrupt the next sell, and overflowing a 32-bit int on revenue if you're in a typed language. Check example 1 by hand: the upgraded unit lands at 100 and gets sold last. If the live OA freezes you on the bucket bookkeeping, StealthCoder is the hedge that gets you unstuck.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Robot Inventory Tracking 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. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Airbnb's OA.
Airbnb reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Robot Inventory Tracking FAQ
What's the trick in Airbnb's Robot Inventory Tracking?+
Track inventory per robot as a price-to-count map. Sell drains the lowest price first, and upgrade just decrements one bucket and increments a higher one. No fancy structure needed. It's careful bookkeeping and simulation in log order.
Do I need a heap or sorted map for this?+
No. The problem says O(logs.length^2) is acceptable, so sorting a robot's price keys on each sell works. A heap adds complexity with upgrades because you'd need lazy deletion. Keep it simple and sort.
What edge cases should I test before submitting?+
Upgrade into a price that already has units, so you merge counts. Sell that spans two or more price buckets. Upgrade that empties the old bucket completely. Multiple robots interleaved. Also confirm revenue is price times units taken, not just price.
How hard is this really?+
Medium at most. There's no tricky algorithm, just a few ways to make small mistakes. The constraints guarantee every sell and upgrade is valid, so you skip error handling. Most failures come from parsing strings or leaving stale zero-count entries.
How do I prepare in 48 hours?+
Write this once from scratch with nested hash maps and run the sample. Then do a couple of other order-of-operations simulation problems. Focus on clean state updates, deleting empty buckets, and converting string fields to numbers up front.