Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

102. Letter Combinations of a Phone Number

MediumDay 29 of 60Recursion & Backtracking

On an old phone keypad, each digit from 2 to 9 maps to a few letters (2 is "abc", 3 is "def", up to 9 which is "wxyz"). Given a string digits, return every letter string that the digits could spell, 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"]
3 choices for "2" times 3 choices for "3" gives 9 strings.
Example 2
Input: digits = ""
Output: []
Constraints
  • 0 <= digits.length <= 4
  • digits[i] is a digit in the range '2' to '9'
Hints
Frequently asked at: Amazon, Google, Uber, Meta
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min