Reported April 2025
Amazongreedy

Buy Servers

Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Amazon OA. Under 2s to a working solution.
Founder's read

You've got an Amazon OA in the next 48 hours and "Buy Servers" just landed in your queue. This is a resource allocation problem that looks deceptively simple on the surface. Candidates often miss the optimization angle and end up with a brute-force solution that times out. The trick is recognizing when you can greedily pick the cheapest option versus when you need to think about constraints. StealthCoder will catch you if you blank on the approach, but knowing the pattern now saves you five minutes of panic during the live OA.

Pattern and pitfall

Buy Servers is fundamentally a greedy or dynamic-programming problem depending on the exact constraints. The most common version: you have a budget, different server types with different costs and specs, and you need to maximize capacity within that budget. The naive approach is to sort by cost and pick the cheapest servers until your budget runs out. That works for simple cases, but Amazon often adds a twist: maybe you need a minimum number of high-performance servers, or there's a bulk discount after N purchases, or you're constrained by rack space. Read the constraints carefully. If it's pure greedy (just maximize units for budget), sort and iterate. If there are dependencies or non-linear costs, you might need DP. StealthCoder can help you spot the pattern fast when you're live, but the real edge is catching the constraint that changes everything.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Buy Servers 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 StealthCoder

Related leaked OAs

⏵ The honest play

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.

Buy Servers FAQ

Is this just a sorting problem?+

Partially. The greedy setup is sort by cost per unit or total cost, then iterate. But Amazon usually adds a constraint like "must have at least X high-spec servers" or "bulk discounts apply after Y units." Read the full problem first. If constraints are linear and independent, greedy works. If they're coupled, you need DP or a smarter greedy pass.

What's the most common pitfall?+

Ignoring constraints and just sorting by lowest cost. Candidates miss discount thresholds, minimum purchase rules, or resource limits on rack space. Re-read the problem twice. The constraint you skip is the one that breaks your solution.

How do I prepare in 48 hours?+

Solve two classic variants: coin change (DP greedy hybrid) and the fractional knapsack problem (pure greedy). Both teach the decision logic. Then study Amazon's job postings for cost-optimization language. That'll hint at what they care about in this problem.

Is there a trick to the budget calculation?+

Yes. Check for off-by-one errors, integer overflow if the budget is huge, and whether prices include tax or extras. Also check if you're maximizing units or minimizing cost. The problem statement will be clear, but re-read the objective twice.

Will I need to handle multiple server types differently?+

Very likely. Amazon doesn't give you one server type. If you have X types with different costs and specs, you might need to pair them (e.g., some cheap, some fast). Think of it as a multi-knapsack variant. Greedy per type first, then combine. That often beats trying a global DP.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Amazon.

OA at Amazon?
Invisible during screen share
Get it