Known Words Matching Phone Digits
Problem statement
You are given a dictionary of known lowercase words and a string of telephone digits. Return the known words that exactly match the digit string using this mapping:
2:abc3:def4:ghi5:jkl6:mno7:pqrs8:tuv9:wxyz
A matching word has exactly one letter for every digit, and each letter maps to the digit at the same position. Return each matching word once, in ascending lexicographic order. Return an empty array when there is no match.
Thread-safety discussion
Discuss how several callers could query a shared dictionary or lookup cache safely. Explain how to publish a complete dictionary snapshot, protect mutable shared state and avoid returning a cached answer from the wrong dictionary version. The judged callable remains a finite sequential lookup and does not require implementing threads.
Function
matchingWords(words: String[], digits: String) → String[]Examples
Example 1
words = ["tree","used","apple"]digits = "8733"return = ["tree","used"]Both tree and used map to 8733. apple has a different length and signature.
Example 2
words = ["a","b","a","d"]digits = "2"return = ["a","b"]The repeated dictionary entry a appears only once in the result.
Constraints
0 <= words.length <= 2000.- Every word contains
1to20lowercase English letters. 1 <= digits.length <= 20; every digit is from2through9.- Dictionary entries may repeat.