43. Letter Combinations of a Phone Number

Given a string consisting of digits from 2 to 9 (inclusive). Return all possible letter combinations that the number can represent.

Mapping of digits to letters is given in first example.

Example 1:

Input : digits = "34"

Output : [ "dg", "dh", "di", "eg", "eh", "ei", "fg", "fh", "fi" ]

Explanation : The 3 is mapped with "def" and 4 is mapped with "ghi".

So all possible combination by replacing the digits with characters are shown in output.

Example 2:

Input : digits = "3"

Output : [ "d", "e", "f" ]

Explanation : The 3 is mapped with "def".

Now Your Turn!

Pick the correct output for the given input

Input : digits = "8"

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= digits.length <= 4
  • digts[i] contains digitd from [2,9].

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

Fun Facts

0
class Solution {
public:
vector<string> letterCombinations(string digits) {
//your code goes here
}
};
Test Case

Input:

Digits