Reported February 2024
Amazongreedy

Find Largest Set of Onion Bags

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 February 2024 and it's a constraint-satisfaction problem disguised as optimization. You're looking at a set or collection problem where the goal is to maximize some property of onion bags while respecting given limits. The trick isn't complex math or a clever algorithm, it's understanding what "largest" actually means in context and avoiding off-by-one errors on the counts. If you blank on the approach during the OA, StealthCoder will flag the core constraint and let you iterate from there.

Pattern and pitfall

This problem likely hinges on either greedy selection (pick bags by size or some metric until you hit a limit) or simulation (track counts, update state, compare outcomes). The pitfall is misinterpreting the constraint: candidates often lock onto the wrong dimension of "largest." The real work is parsing what the problem considers a valid bag, what limits apply, and how to compare sets. It's not a binary search or DP heavy-hitter, it's more about careful state tracking and logical correctness. StealthCoder serves as your safety net if you misread the problem live and need to pivot quickly.

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 Largest Set of Onion Bags 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 Largest Set of Onion Bags FAQ

Is this a greedy problem or do I need dynamic programming?+

Greedy is your starting point. Try sorting by the constraint (bag size, count, etc.) and selecting in order until you hit the limit. If that fails test cases, then reconsider. DP is rarely the answer here unless the problem asks for count of ways or optimal subsets with overlapping subproblems.

What's the most common mistake candidates make on this one?+

Misunderstanding the definition of "largest set." Read carefully: is it total number of bags, total weight, maximum bag size, or something else. One wrong interpretation kills your entire solution. Re-read the problem twice before coding.

How much time should I spend on this during the OA?+

Parse the problem in 2-3 minutes, write a solution in 10-15, then test on examples for 5. If you're stuck after 15 minutes, outline your approach and move on. Amazon values iteration and correctness, not speed.

Is this still being asked at Amazon in 2024?+

Yes. February 2024 report confirms it. Amazon leans on constraint and set problems as part of their screening. Expect variations on inventory, selection, or resource allocation themes.

What edge cases should I test before submitting?+

Empty input, single bag, all bags identical, limit of zero, and limits that allow no valid bags. Off-by-one errors on counts are common. Run through the examples carefully with your code before final submit.

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