Letter Combinations of a Phone Number
Given a string S containing digits from 2 to 9 inclusive. Your task is to find all possible letter combinations that the number could represent.
A mapping from Digits to Letters (just like in Nokia 1100) is shown below. Note that 1 does not map to any letter.
Input format:
The first line of input contains an integer ‘T’ denoting the number of test cases.
Then the 'T' test cases follow.
The first and only line of each test case contains string S.
Output Format
For each test case, the list containing all the combinations of letters will be printed.
The output of each test case is printed in a separate line.
Note
You don’t have to print anything, it has already been taken care of. Just implement the function.
The output strings can be returned in any order.
Constraints:
1 <= T <= 10
1 <= |S| <= 10
2 <= S[i] <=9
Where |S| is the length of string 'S" and 'S[i]' represents the element of the string S.
Time Limit: 1 sec
CodingNinjas
author
2y
Recursion, Backtracking, with memorization java
CodingNinjas
author
2y
Backtracking approach
The idea is to find all possible combinations of letters using backtracking.
Backtracking is an algorithm to find all possible solutions by exploring all potential candidates. If ...read more
Help your peers!
Add answer anonymously...
Top Nagarro Software Developer interview questions & answers
Popular interview questions of Software Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app