Ways to Group Parcels
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Amazon asked this in March 2024, and it's a grouping problem that looks simpler than it plays. You're given parcels with properties (weight, destination, size, or similar), and you need to count how many distinct ways they can be grouped under some constraint. The hash-table pattern is the foundation here, but the trick is figuring out what makes two groupings different. This is the kind of problem where candidates blank on the constraint interpretation, so StealthCoder is your safety net if that happens live.
Pattern and pitfall
The core pattern is hash-table: you'll normalize parcel attributes into a key (like a tuple or string representation), then count occurrences or map parcels to groups. The catch is usually combinatorial. You're not just grouping by one attribute; you're counting valid assignments. Common pitfalls: treating it as a simple group-by when it's actually about permutations or partitions, or misreading whether order matters. If the problem is 'how many ways to partition n parcels into k groups,' you'll need combinatorics on top of your hash logic. Build a hash map first to deduplicate and characterize parcels, then apply counting logic. StealthCoder will highlight the exact constraint from the problem text live, which often kills candidate momentum.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Ways to Group Parcels 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 for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Amazon's OA.
Amazon reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Ways to Group Parcels FAQ
Is this a dynamic programming problem or pure hash-table?+
It's hash-table first. DP appears only if the problem asks for optimal groupings under cost constraints. Start by mapping parcel attributes to counts, then decide if you need DP for the assignment phase. Most candidates overfit to DP; Amazon usually just wants the hash and counting logic.
What's the most common constraint candidates miss?+
Whether two groups are distinguishable (labeled vs. unlabeled partitions). If groups are unlabeled, you divide by k! at the end. If labeled, you don't. Re-read the problem statement once for this specifically.
How do I test if my grouping logic is right?+
Trace a small example by hand. Take 3 parcels, manual partition them all ways, count them, then verify your code matches. Candidates often miss edge cases like single-parcel groups or all parcels in one group.
Can I solve this in 30 minutes if I haven't seen it before?+
Hash-table grouping, yes. Counting the valid arrangements, probably not cleanly. The hash is 10 minutes. The combinatorial logic eats the rest. Aim for a correct brute-force hash solution first, optimize after.
Does Amazon care about the algorithm name or just the result?+
Result and correctness. You don't need to name it as 'Stirling number of the second kind' or whatever. Just be precise about your counting logic and explain the constraint you're respecting.