This question evaluates string processing, mapping and grouping competencies and the ability to design efficient encodings for detecting collisions, assessing practical application of algorithmic techniques. It is commonly asked in the Coding & Algorithms domain because it probes algorithmic efficiency, data-structure selection, and handling of input-size and performance constraints.
On a classic phone keypad (T9), letters map to digits:
2: ABC
,
3: DEF
,
4: GHI
,
5: JKL
,
6: MNO
,
7: PQRS
,
8: TUV
,
9: WXYZ
Given a list of lowercase words, convert each word into its digit string (e.g., "tree" -> "8733").
Return all groups of words that map to the same digit string (i.e., collisions). Only include groups of size >= 2.
words: string[]
(lowercase a–z)
1 <= len(words) <= 2 * 10^5
1 <= len(word) <= 30
["tree", "used", "apple", "vase"]
tree -> 8733
,
used -> 8733
,
apple -> 27753
,
vase -> 8273
[["tree", "used"]]