Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
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.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.