Asked at The Voleon Group
Theory: Algorithms Under a Complexity BoundRead the problem, hints and solution here. The editor needs a bigger screen: open this page on a laptop to write and run your code.
Available in Python and C++. You are solving it in Python. Switch to C++
A Voleon quant researcher technical screen opened with this problem in 2026. It is the warm-up before the statistics: the interviewer wants to see you reach for the right data structure without being told, and move on in a few minutes.
Two words are anagrams when one is a rearrangement of the other, so they use the same letters the same number of times. Given a list of lowercase words, group the words that are anagrams of each other.
Implement group_anagrams(words) returning a list of groups, where each
group is a list of words. Order the groups by the first appearance of any of
their members in the input, and keep the words inside a group in input
order. A word that appears twice is two separate entries in the same group.
The empty string is an anagram of itself. An empty input returns an empty
list.
group_anagrams(["eat", "tea", "tan", "ate", "nat", "bat"])
# [["eat", "tea", "ate"], ["tan", "nat"], ["bat"]]
group_anagrams(["ab", "ba", "ab"])
# [["ab", "ba", "ab"]] (the repeat is a second entry, not a merge)
a to z only.std::vector<std::vector<std::string>> group_anagrams(
const std::vector<std::string>& words);
The words arrive as a std::vector<std::string> and the result is one
vector per group, in the same order rules as above.