LeetCode 49 Group Anagrams - Why Naive Fails

The trap

You might compare every pair of strings to check if they're anagrams. For each pair, you'd compare character counts in O(k)O(k) time where kk is string length.

With nn strings, that's O(n2)O(n^2) pairs. Total: O(n2k)O(n^2 \cdot k).

For n=104n = 10^4 strings of length 100100, that's roughly 101010^{10} operations. Way too slow.

You need a way to identify anagrams without comparing every pair directly.