Reported July 2026
Amazonhash table

Group Anagrams

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

Pairwise comparing every string against every other one dies fast when the list gets big, and that's the trap in this Amazon OA question reported in July 2026. Group Anagrams is a hash-table problem with a twist: you can't sort the characters. The prompt tells you to build a 26-entry count vector and use it as the key. So the work is one pass, one map, done. If your head goes blank under the timer, StealthCoder runs invisibly on your desktop and gives you a working solution as a safety net. Know the shape first, though.

The problem

Group the strings in strs so that two strings appear in the same group exactly when they are anagrams.
For this exercise, assume every string contains only lowercase English letters. Do not sort the characters of a string to determine its group. Build a fixed 26-entry character-count vector and use that vector as the grouping key.

Examples
Example 1
strs = ["eat","tea","tan","ate","nat","bat"]
return = [["ate","eat","tea"],["bat"],["nat","tan"]]

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is the key. For each string, make an array of 26 zeros, add one to the slot for each letter, then turn that vector into something hashable, like a tuple or a joined string with separators. Anagrams produce identical vectors, so they land in the same bucket. Total cost is O(n * k) for n strings of average length k, which beats sorting each string at O(n * k log k). The classic pitfall is joining counts without a delimiter, so 1 and 11 collide with 11 and 1. Use commas or a tuple. Another one is breaking the rule and sorting anyway, since this version explicitly bans it. Also note the example output is ordered, so check whether order matters before you add extra sorting. If you freeze mid-assessment, StealthCoder is the hedge that can hand you the full map-of-vectors solution live.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Group Anagrams 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 by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as group anagrams. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Amazon's OA.

Amazon reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Group Anagrams FAQ

What's the trick in Group Anagrams?+

Use a canonical key for each string. Here the prompt forces a 26-slot count vector instead of sorted characters. Strings with the same letter counts produce the same vector, so a hash map from vector to list of strings does all the grouping in a single pass.

How hard is this Amazon OA question really?+

It's medium at most. The logic is short once you see the hash map idea. The difficulty is following the constraint about not sorting and building a hashable key correctly. Most failures come from key collisions or mutating a list that can't be a dictionary key.

Why can't I use a list as the dictionary key?+

Lists are mutable and unhashable in languages like Python, so convert the count vector to a tuple or a delimited string first. In other languages, build a string key such as the counts joined with commas. Skipping the delimiter causes false collisions.

What's the time complexity I should state?+

O(n * k) time, where n is the number of strings and k is the longest string length, since each character is counted once. The key is a fixed 26 entries, so key handling is constant per string. Space is O(n * k) for the map and output.

How do I prepare for this in 48 hours?+

Write it from scratch twice without notes. Practice the count-vector key, the delimiter detail, and the empty string case, which gives an all-zero vector and still groups correctly. Then test the example from the prompt and check whether output order matters.

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