Group Students
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Amazon's Group Students problem hit the OA circuit in January 2024, and it's a hash-table play that looks deceptively simple on first read. You're partitioning a list of students into groups based on some attribute, and the trap is thinking you need to sort or search when a hash map gets you there in linear time. If you blank on the exact grouping logic during the live OA, StealthCoder reads the problem statement and surfaces the grouping key immediately, so you don't lose 20 minutes staring at the wrong approach.
Pattern and pitfall
The core pattern is hash-table bucketing. You iterate through students once, use a hash map to bucket them by their grouping criterion (likely grade, enrollment date, or score range), then return the grouped result. The trick candidates miss is trying to presort or use nested loops when a single pass with a dictionary solves it in O(n) time and O(n) space. The second trap is handling edge cases like empty groups or maintaining insertion order (Python 3.7+ dicts preserve order, but other languages don't). During the OA, if you get stuck on the grouping key or the return format, StealthCoder gives you the exact structure so you can code confidently instead of guessing.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Group Students 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 StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as group anagrams. If you have time before the OA, drill that.
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.
Group Students FAQ
Is this really just a hash map problem, or is there a sorting step I'm missing?+
Pure hash map. Grouping by a single attribute is one pass. If the expected output is sorted by group name or student count, that's a secondary sort, but the grouping itself doesn't require it. Most solutions don't. Check the examples carefully.
What if two students share the same grouping attribute?+
They go into the same bucket. That's the entire point. Use a list or set as the hash value, append students to it. If order within groups matters, preserve insertion order or sort the group afterward.
How do I handle the return format for multiple groups?+
Return a dictionary, 2D array, or list of lists depending on what the problem asks. Most likely a dict with the grouping key as the key and a list of student objects (or IDs) as the value. Read the examples.
Can I solve this without a hash table?+
Technically, yes. Sorting by the grouping attribute and then iterating gives you adjacent groups. But that's O(n log n) and more code. Hash table is the intended pattern and it's faster.
Is this problem still appearing in Amazon OAs, or is it dated?+
It appeared in January 2024. Hash-table grouping is a staple because it tests whether you know the right data structure. Expect similar 'partition by attribute' problems on any Amazon technical round.