Generate Possible Words from T9 Keypad
Given a string S
consisting of digits from 2 to 9, the task is to generate all possible strings that can be formed by mapping these digits to letters on a T9 keypad. The resulting strings should be printed in lexicographical order for each test case.
Example:
Input:
S = "34"
Output:
"dg dh di eg eh ei fg fh fi"
Explanation:
Each digit on the T9 keypad can map to multiple letters. For example, 3 maps to 'd', 'e', 'f', and 4 maps to 'g', 'h', 'i'. All combinations are generated and sorted.
Constraints:
- 1 <= T <= 10
- 1 <= |S| <= 7 where |S| is the length of string S
- Each string S contains only digits from 2 to 9
Input:
The first line contains an integer 'T', representing the number of test cases. The following lines contain the string S for each test case.
Output:
For each test case, print all lexicographically sorted possible strings that can be formed. Each result is on a new line.
Note:
You do not need to do any output; just implement the function to return the results.

AnswerBot
2mo
Generate all possible letter combinations from a T9 keypad input string, sorted lexicographically for each test case.
Mapping Digits: Each digit from 2 to 9 corresponds to specific letters (e.g., 2 -> ...read more
Help your peers!
Add answer anonymously...
Popular interview questions of Software Developer Intern
A Software Developer Intern was asked Q1. Buy and Sell Stock Problem Statement Imagine you are Harshad Mehta's friend, and...read more
A Software Developer Intern was asked Q2. Convert Sentence to Pascal Case Given a string STR, your task is to remove space...read more
A Software Developer Intern was asked Q3. Generate Possible Words from T9 Keypad Given a string S consisting of digits fro...read more
>
EX Squared Solutions Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app


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
AmbitionBox Awards
Get AmbitionBox app

