Min Cost
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Amazon's Min Cost question showed up in December 2024 OAs, and it's testing whether you'll reach for greedy or get trapped in a local optimum. You've got a live OA in the next 48 hours, so this pattern matters. The trick is almost always about choosing the lowest immediate cost at each step, but the catch is knowing when that actually leads to the global minimum. StealthCoder will be your safety net if you blank on the approach during the assessment.
Pattern and pitfall
Greedy problems on Amazon OAs typically present a scenario where you're making sequential choices: pick items, process transactions, merge operations, assign resources. The pattern is to always pick the minimum (or maximum) cost option available at each step and commit to it. The pitfall: greedy doesn't always work. You need to verify that the local optimum compounds into a global optimum. Common setups include sorting by cost first, then iterating through choices. Amazon loves this because it mirrors real warehouse and logistics decisions. During the live OA, if you're unsure whether greedy is correct, StealthCoder will show you the pattern and a working solution so you can code with confidence instead of guessing.
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 Min Cost 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.
Min Cost FAQ
Is this definitely a greedy problem?+
It's flagged as greedy, which means at each step you're picking the minimum cost option. Verify this works by tracing through a small example. If always picking the cheapest choice leads to the right answer, you're good. If not, it's dynamic programming.
What's the most common pitfall on Min Cost at Amazon?+
Greedy fails when future choices depend on earlier choices in a way that forces you to backtrack. If sorting by cost and iterating left-to-right solves it, great. If you need to reconsider past decisions, you need DP or a different approach.
How do I code this in under 20 minutes?+
Sort the costs or options in ascending order, iterate once, accumulate the minimum cost at each step. Write a single loop. Test on the example. If it works, submit. Don't overthink edge cases during the OA itself.
What if the greedy approach fails on the example?+
Step back. Is there a constraint or dependency you missed. Reread the problem for hidden rules about what choices block or enable future choices. If greedy truly fails, pivot to DP or BFS.
Should I optimize for time or space on an Amazon OA?+
Time. Amazon cares about throughput and latency in production. A greedy O(n log n) sort-and-iterate approach beats a slower DP. Code for clarity and correctness first, then optimize if you have time.