Letter Combinations of Phone Number
Practice this coding question on Coding Gurukul.
Problem statement
A telephone directory stores short mnemonic labels. Each digit in a keypad code can represent any letter printed on that key, and the directory needs every candidate label. Your task Generate all letter combinations represented by the input digits, choosing exactly one letter per digit. Important details Use 2:abc, 3:def, 4:ghi, 5:jkl, 6:mno, 7:pqrs, 8:tuv, 9:wxyz. Keep digit positions in their original order. A repeated digit still makes an independent choice at each position. Print lowercase strings in lexicographic order without duplicates. Worked example For 24, the first letter comes from abc and the second from ghi. The nine labels are ag, ah, ai, bg, bh, bi, cg, ch and ci.
Input format
One nonempty string of digits from 2 through 9.
Output format
Print the number of labels followed by one label per line in lexicographic order.
Constraints
1 <= number of digits <= 4.
Sample input
24
Sample output
9 ag ah ai bg bh bi cg ch ci
Sign in to run or submit a solution in C++, Java or Python.