Sum Max Plus Min After Decrement Operations
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Amazon asked this in March 2026: given an array and a request count, you repeat an operation that many times. Each operation finds the max and min, adds them together, and decrements the max. You accumulate these sums across all requests. The trap is thinking about it as a simulation when there's usually a mathematical pattern hiding in the decrements. StealthCoder can spot the pattern in real time if you freeze during the OA.
The problem
You are given an integer array arr and an integer requests. Repeat the following operation exactly requests times: Return the final accumulated answer. Function Description Complete the function sumMaxPlusMinAfterOperations in the editor below. sumMaxPlusMinAfterOperations has the following parameters: Returns long: the accumulated sum. First add 1 + 2 = 3 and decrement the 2 to 1. Then add 1 + 1 = 2. The total is 5. The current maximum and minimum are both 3, so the answer increases by 6.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The core trick is recognizing that the max element decreases by 1 each operation, so it follows a predictable sequence. Instead of simulating requests iterations (which can be huge), you can derive a formula. After k operations, the original max has dropped to max - k, and you're summing (max - i) + min for each iteration from 0 to k-1. This collapses into a closed-form calculation using arithmetic series math. The pitfall is writing a naive loop when the answer demands prefix sums or direct arithmetic. StealthCoder handles the algebra instantly if you blank on the formula.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Sum Max Plus Min After Decrement Operations 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 StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Amazon's OA.
Amazon 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.
Sum Max Plus Min After Decrement Operations FAQ
Do I really need to simulate every request?+
No. The max decrements predictably. Use arithmetic series: sum of (max - i) for i from 0 to requests-1 gives you requests * max - requests*(requests-1)/2. Add min * requests. One formula, no loop.
What if requests is massive, like 10^9?+
That's why simulation fails. A loop times out. The formula runs in O(1). That's the test's real constraint. The problem setters are checking if you recognize the pattern, not if you can code a for loop.
Does the min ever change?+
Not in this problem. Only the max decrements. The min stays constant across all requests. So its contribution is simply min * requests added to your total.
What's the edge case I'll miss?+
If requests is 0, return 0. If the array has only one element, max and min are the same, so you're adding that value twice per operation. Watch integer overflow: use long arithmetic from the start.
Is this actually hard, or am I overthinking?+
It's medium at best once you see the math. The difficulty is spotting that you don't simulate. If you code a loop and it times out, you'll know instantly. That's when StealthCoder's formula lookup saves you.