Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Letter Combinations of a Phone Number

Medium

Topics
StringBacktrackingHash Table

Given a string of digits from 2-9, return all letter combinations the number could spell (phone keypad mapping). Return an empty result for an empty input. Order does not matter.

Example 1

Input:  digits = "23"
Output: ["ad","ae","af","bd","be","bf","cd","ce","cf"]

Example 2

Input:  digits = ""
Output: []

Constraints

  • 0 <= digits.length <= 4
  • digits[i] is in the range 2-9.
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access