Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
T9 Keypad Mapping
00:00
5 left

T9 Keypad Mapping

MediumPython

Problem

How would you convert a string of digits into the corresponding T9 text message sequences?

Implement letter_combinations(digits) using the standard phone keypad mapping from digits 2 through 9 to letters. Return all possible letter strings in depth-first generation order. For an empty input, return an empty list.

Examples: "23" returns ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"]; "7" returns ["p", "q", "r", "s"].

Constraints: 0 <= len(digits) <= 8; every character is a digit from 2 through 9.

Constraints

  • 0 <= len(digits) <= 8
  • Every character in digits is between '2' and '9'
  • Return sequences in depth-first keypad order
  • The output contains the Cartesian product of the mapped letters

Function Signature

def letter_combinations(digits):
Interviewer

Your question is T9 Keypad Mapping. Start with the requirements in the Question tab.

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.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.