Reported September 2024
Amazongreedy

Find Maximum Calories

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

Amazon's 'Find Maximum Calories' problem hit the OA circuit in September 2024, and it's a greedy trap. You're likely picking items to maximize total calories under a weight or count constraint, but the naive 'take the biggest' approach fails. The trick is sorting by efficiency (calories per unit weight, or per item count) and greedily selecting. If you blank on the pattern during the live OA, StealthCoder will surface the right sort order in seconds. This is the kind of problem that looks simple until you realize your first solution doesn't pass all test cases.

Pattern and pitfall

The pattern is greedy selection with a secondary sort. The common miss: candidates sort by raw calories and hit time-limit or logic failures on edge cases where smaller, denser items pack more value. You need to compute calories per unit (weight, count, or cost) and sort descending, then greedily pick until you hit the constraint. Watch for integer overflow if calories are large, and test boundary cases where the last item doesn't fit. The algorithm is O(n log n) for sort, O(n) for selection. If you freeze mid-OA and can't recall whether to sort ascending or descending, or you're stuck debugging a greedy choice, StealthCoder reads the problem and constraints from your screen and tells you the right formula immediately.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Find Maximum Calories 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 for the candidate who got the OA invite this morning and has 72 hours, not six months.

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. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Find Maximum Calories FAQ

Is this really just a sorting problem?+

Mostly, yes. Sort by calories per unit (calories divided by weight, count, or cost, depending on what the problem gives you), then iterate greedily. The hard part is figuring out which metric to divide by. Read the constraints carefully.

What's the common gotcha?+

Sorting by raw calories instead of efficiency. You'll pass small test cases and fail on cases where a light, calorie-dense item beats a heavy one. Also watch for fractional efficiency: use multiplication to avoid floating-point errors.

How do I prepare in 48 hours?+

Know the greedy pattern. Practice one knapsack variant and one activity-selection problem. Understand why greedy works for this and when it doesn't. Then stop. You're not going to memorize edge cases.

Will this show up as a follow-up or variation?+

Possibly. Amazon likes to ask 'now do it with two constraints' or 'maximize calories and minimize sodium.' The pattern holds: compute a compound efficiency metric and sort. If it mutates during the OA, pause and re-read.

Do I need to handle ties in efficiency?+

Test cases probably include ties. Stable sort or secondary sort (e.g., by calories descending) breaks them consistently. It matters for deterministic output but usually both orderings are accepted.

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