Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Phone Dial Pad Combinations

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Phone Dial Pad Combinations. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Signifyd's verification workflows may need to compare a phone number with candidate words entered through a standard mobile keypad. Given a digit string and a list of alphabetic strings, return every string whose letters map exactly to the phone number's digits.

Use this standard mapping: 2 = abc, 3 = def, 4 = ghi, 5 = jkl, 6 = mno, 7 = pqrs, 8 = tuv, and 9 = wxyz. Matching is case-insensitive, and the returned strings must preserve their original spelling and input order. A candidate matches only when it has the same length as the phone number and every character maps to the corresponding digit. Candidates contain letters only.

Formal Specification

Implement filter_phone_words(phone_number, candidates), where phone_number is a string containing digits from 2 through 9, and candidates is a list of strings. Return a list containing all matching candidates. Duplicate candidates should appear as many times as they occur in the input.

Examples

Example 1

Input: phone_number = "43556", candidates = ["hello", "gel", "world", "HeLlO"]
Output: ["hello", "HeLlO"]

hello and HeLlO both map to 43556; gel has the wrong length.

Example 2

Input: phone_number = "8733", candidates = ["tree", "used", "test", "true"]
Output: ["tree", "used"]

Both tree and used map to 8733.

Constraints

  • 1 <= len(phone_number) <= 10^5
  • 1 <= len(candidates) <= 10^4
  • Each candidate length is at most 10^5
  • The total number of candidate characters is at most 10^6
  • phone_number contains only digits 2 through 9
  • Candidates contain alphabetic English letters only

Constraints

  • 1 <= len(phone_number) <= 10^5
  • 1 <= len(candidates) <= 10^4
  • Each candidate length is at most 10^5
  • The total number of candidate characters is at most 10^6
  • phone_number contains only digits 2 through 9
  • Candidates contain alphabetic English letters only

Function Signature

def filter_phone_words(phone_number, candidates):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output