Reported January 2024
Amazongreedy

Get Trucks for Items

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 asked this in January 2024, and it's a logistics problem dressed up in simple language. You get a list of items with weights, a set of trucks with capacity limits, and you need to assign items to trucks efficiently. The catch: it's not just about fitting things in. You're optimizing for some metric, usually minimizing trucks used or maximizing utilization. If you blank on the greedy approach during the OA, StealthCoder will surface the pattern instantly so you don't lose the next 20 minutes to panic.

Pattern and pitfall

This is a bin-packing variant, and bin-packing is NP-hard, which means there's no perfect polynomial solution. But the OA isn't asking for perfect. It's testing whether you know the greedy heuristics: First Fit Decreasing (sort items by weight descending, pack each into the first truck that fits) or Best Fit (pack each item into the truck with the least remaining space that still fits it). The trick is recognizing that a naive greedy won't always win, but it's fast and good enough. Common pitfall: over-engineering with dynamic programming when a greedy pass solves it in O(n log n). StealthCoder handles the edge cases (items larger than any truck, empty lists, trucks with identical capacity) so you stay focused on the algorithm choice, not defensive coding.

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 Get Trucks for Items 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.

Get Trucks for Items FAQ

Is this really asking me to minimize truck count, or is it something else?+

The problem likely wants minimum trucks used. That's the canonical bin-packing goal. But read the output spec carefully, sometimes Amazon wants the actual assignment (item to truck mapping) or a utilization score. The problem statement you see will be clear on this. Don't assume.

Should I sort the items first?+

Yes, almost always. First Fit Decreasing (largest items first) beats naive greedy significantly. Sorting is O(n log n), packing is O(n), so it's free optimization. Do it.

What if an item is heavier than every truck's capacity?+

The problem should clarify whether this is valid input. If it is, you either return an error, skip the item, or assume it won't happen. Check the constraints. If ambiguous, ask clarification or handle it explicitly in your code.

Is this asked often at Amazon, or was it a one-off in January?+

Bin-packing and resource allocation are core to Amazon's logistics domain. Variants appear regularly. The specific framing changes, but the pattern (greedy + sorting) is stable.

How do I prepare in 48 hours if I haven't seen bin-packing before?+

Learn First Fit Decreasing and code it once. Understand why it works (larger items block fewer future items). Trace through a small example by hand. That's enough. The OA will guide you with examples.

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