LinkedIn VO Interview Question: Find Words Matching a Phone Number

15 Views
No Comments

Given the standard mapping from English letters to digits on a phone keypad, write a program that outputs all words that can be formed from an n-digit phone number from the list of given words, considering the mapping mentioned above.

KNOWN_WORDS = ['careers', 'linkedin', 'hiring', 'interview', 'linkedgo']

phoneNumber: 2273377

Output: ['careers']

phoneNumber: 54653346

Output: ['linkedin', 'linkedgo']

This problem asks you to match words against a phone number using the classic letter-to-digit keypad mapping. A straightforward solution is to encode each candidate word into its digit string and compare it with the given phone number. With a list of words, this is typically done by scanning all candidates and checking whether their encoded form matches exactly. A hash map from encoded digits to words can make lookups even faster if multiple queries are involved.

END
 0