Letter Combinations of a Phone Number Problem Statement

You are 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, based on the mapping from digits to letters, similar to the traditional mobile phone keypads.

Input:

The first line of input includes an integer 'T', which represents the number of test cases.
Each of the next 'T' lines contains a single string 'S', representing the sequence of digits.

Output:

For each test case, output a list of all possible letter combinations.
Print the results for each test case on a new line.

Example:

Input:
T = 1
S = "23"
Output:
["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"]
Explanation:

Digit '2' maps to letters "abc" and digit '3' maps to "def". Thus, all combinations of these letter pairs are shown.

Constraints:

  • 1 <= T <= 10
  • 1 <= |S| <= 10
  • 2 <= S[i] <= 9

Where |S| is the length of the string 'S', and 'S[i]' denotes the element of the string S.

Note: You don’t have to print anything; it is handled internally. Implement the function accordingly, and the output can be returned in any order.

AnswerBot
4mo

Given a string of digits, find all possible letter combinations based on phone keypad mapping.

  • Use a recursive approach to generate all possible combinations of letters for each digit in the input stri...read more

Help your peers!
Select
Add answer anonymously...

Nagarro Software Developer interview questions & answers

A Software Developer was asked 8mo agoQ. Explain Kafka and how you would implement it.
A Software Developer was asked 9mo agoQ. Is the directory a file?
A Software Developer was asked 9mo agoQ. What is memory segmentation?

Popular interview questions of Software Developer

A Software Developer was asked 8mo agoQ1. Explain Kafka and how you would implement it.
A Software Developer was asked 9mo agoQ2. Is the directory a file?
A Software Developer was asked 9mo agoQ3. What is memory segmentation?
Nagarro Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits