Maximum Book Copies
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
You're looking at an Amazon OA that tracks book inventory updates and asks for the running maximum after each one. The problem gives you a stream of updates, and you need to return the peak book count seen so far at each step. It's a straightforward max-tracking problem, but the catch is doing it efficiently as updates come in. StealthCoder will catch the pattern instantly if you blank on the approach, but the logic is clean once you see it.
The problem
Amazon invests in the success of entrepreneurs, artisans, and small business selling in the Amazon Store. Some of these small business are book stores. Amazon maintains a protal, where the booksellers can update their inventories. An update received from the portal is represented by the array portalUpdate, whose valuess indicate the following: Given the list of portal updates, the task is to return the maximum copies of any book in the inventory after each update. Function Description Complete the function maximumBookCopies in the editor. maximumBookCopies has the following parameter: Returns int[n]: an array of integers representing the maximum copies of any book after each update
Reported by candidates. Source: FastPrep
Pattern and pitfall
This is a running maximum problem. You iterate through the portal updates once, maintaining the highest book count observed up to each point. The trick is that you're not tracking individual books, just the maximum copies of any single book at each step. Most candidates overthink this and try to build a hash map of all books when they should just track one number. The pattern is prefix-max: at each update, you either keep the previous maximum or update it if the new value is larger. One pass, O(n) time, O(n) space for output. StealthCoder handles the mental overhead if the wording throws you, but the implementation is just a loop with a max comparison.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Maximum Book Copies 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 by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Amazon's OA.
Amazon reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Maximum Book Copies FAQ
What does 'maximum copies of any book after each update' mean?+
It means you track the highest inventory count for a single book title seen so far. After update one, the max is that value. After update two, the max is the larger of the two. You're building an array of running maximums, not tracking individual book names.
Do I need a hash map to solve this?+
No. A hash map would be overkill. You just need a single variable to hold the current maximum and update it as you scan through the updates. One pass, no complex data structure needed.
What's the time complexity I should target?+
O(n), where n is the number of updates. You iterate through the array once and perform constant-time operations at each step. Space is O(n) for the output array only.
Is this problem still asked at Amazon?+
Yes. It's a real OA problem reported from Amazon. It's simple, but Amazon uses these running-aggregate problems to filter for basic algorithmic thinking and code clarity. Don't overcomplicate it.
How do I prepare in 48 hours?+
Understand prefix sums and running maximums. Code this problem once cleanly. Then check your edge cases: empty input, single update, all same values. That's enough. It's not a hard problem, just a pattern recognition test.