Given known_words and a phone-keypad letter-to-digit mapping, return the words from known_words that map to a given input number (e.g. "54653346" -> ["linkedin", "jjmldfhm"]); optimize for repeated calls
Asked in the Phone screen stage. Reported follow-up: How could this be optimized for repeated calls?
Implement words_for_number(known_words, mapping, input_number). known_words is a list of lowercase strings, mapping maps each character to one digit string, and input_number is a digit string. Return matching words in their original order. Repeated calls with the same known_words and mapping should reuse a precomputed index.
def words_for_number(known_words, mapping, input_number):