Skip to main content
All Questions

Given a string of digits from 2 to 9 and the classic phone keypad mapping, return all possible letter combinations the number could represent.

Medium
Unlock detailed company stats for this questionUpgrade

On a phone keypad, each digit from 2 to 9 maps to a few letters:

2: abc 3: def 4: ghi 5: jkl 6: mno 7: pqrs 8: tuv 9: wxyz

Given a string digits containing only digits from 2 to 9, return every letter string the digits could spell, taking one letter for each digit. Return the strings in any order. If digits is empty, return an empty list.

Example 1

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

Each of the three letters for 2 pairs with each of the three letters for 3.

Example 2

Input: digits = "" Output: []

Constraints

  • 0 <= digits.length <= 4
  • Each character of digits is a digit from 2 to 9.

Related courses

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.

Course

System Design Interviews

Learn how to answer the latest system design questions across product, infrastructure, and AI domains. Features in-depth video examples, written breakdowns, and helpful reference patterns. Watch senior engineers and managers answer these questions in mock interview videos.