Reported January 2026
Motivehash table

Group Anagrams

Reported by candidates from Motive's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Motive OA. Under 2s to a working solution.
Founder's read

Motive reported this one in January 2026, and it looks harder than it is. Group Anagrams reduces to one question: what key do two anagrams share? Once you have that key, a hash table does the rest. The twist here is the output rule. Sort each group, then sort the groups by their first string, so your answer matches the expected one exactly. If you've got an OA invite and 48 hours, this is a pattern worth locking in. And if you blank mid-assessment, StealthCoder runs invisibly on your desktop and can hand you the approach in real time.

The problem

Group the strings in strs so that two strings appear in the same group exactly when they are anagrams.
For deterministic output, sort the strings inside each group and then sort the groups lexicographically by their first string.

Function
groupAnagrams(strs: String[]) → String[][]

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

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is a canonical key. Sort the characters of each string, and every anagram lands on the same key. Map key to list of originals in a hash table. That's O(n * k log k) for n strings of length k. A faster key is a 26-count tuple, which gives O(n * k) for lowercase letters. The pitfall is the deterministic output the Motive version demands. Sort the strings inside each group, then sort the groups by their first element. Skip that and you'll fail tests even with correct grouping. Another trap is the empty string. The input [""] must return [[""]], and the sorted-key approach handles it naturally since the key is just empty. Don't use a list as a dict key in Python. Join the sorted characters into a string or use a tuple. If you freeze on the final sorting step during the live OA, StealthCoder is the hedge that shows you the full flow.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

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. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

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 Motive's OA.

Motive 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 Anagrams FAQ

How hard is Group Anagrams really?+

Easy to medium. The core idea is one hash map and one canonical key. Most people who struggle already know the idea but trip on the output ordering rule. Read the sorting requirement twice before you submit.

What's the trick to solving it fast?+

Pick a key that's identical for all anagrams. Sorting each string's characters works and takes two lines. Store key to list in a dictionary, then collect the values. That's the whole algorithm before the final ordering step.

Do I need to sort the output for the Motive version?+

Yes. The problem says to sort strings inside each group, then sort groups lexicographically by their first string. Without it your answer can differ from the expected output even if the grouping is right. Do it after building the map.

Sorted key or count key, which should I use?+

Sorted key is simpler and fine for most inputs. A count tuple of 26 letters is faster for long strings, but only if the characters are lowercase letters. If the input doesn't guarantee that, stick with the sorted string.

How do I prepare for this in 48 hours?+

Write it from scratch twice, once with each key type. Then test the edge cases: a single empty string, duplicates, and one-character strings. Finish by coding the output sorting step so it's automatic under pressure.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Motive.

OA at Motive?
Invisible during screen share
Get it