Group Strings By Anagram Signature
Company: Okx
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: Practice grouping strings by anagram signature in a coding interview, including sorting-based and frequency-vector approaches. The problem is useful for reviewing hash maps, deterministic grouping, duplicate words, and time-complexity trade-offs.
Constraints
- Words contain lowercase English letters.
- Duplicate words should be preserved.
Examples
Input: (['eat','tea','tan','ate','nat','bat'])
Expected Output: [['ate','eat','tea'],['bat'],['nat','tan']]
Input: ([''])
Expected Output: [['']]
Input: (['a'])
Expected Output: [['a']]
Input: (['abc','bca','cab','foo'])
Expected Output: [['abc','bca','cab'],['foo']]
Input: (['duh','ill'])
Expected Output: [['duh'],['ill']]
Input: (['aa','aa','a'])
Expected Output: [['a'],['aa','aa']]
Input: ([])
Expected Output: []
Input: (['ab','ba','abc','cba','bca'])
Expected Output: [['ab','ba'],['abc','bca','cba']]
Hints
- A frequency tuple can improve the per-word signature cost for fixed alphabets.
- Normalize the output order for deterministic tests.