Array ( [0] => [1] => questions [2] => Strings [3] => Combination-of-strings-used-to-dial-a-number ) Strings | Combination of strings used to dial a number | THE INQUISITIVE





Combination of strings used to dial a number

LEVEL:Beginner

Description

Given a number N. You have to print the all the combination of strings that can be used to dial the given number.

Input Format

First line contains the number N.

Output Format

Print all the combinations.


Example 1:

Input
2
Output
A B C
Example 2:

Input
23
Output
AD AE AF BD BE BF CD CE CF
Example 3:

Input
24
Output
AG AH AI BG BH BI CG CH CI

oops

Login to see Discussion




Approach

step-i) Create a HashMap which keeps the numbers as keys and respective characters as values
step-ii) create a string builder str
step-iii) call the method print_answer passing N,i which is 0,hashmap and str as parameters
step-iv) if i equal to length of string print string and return
step-v) initialize another string s with value of hashmap whose key is character at index i of given string
step-vi) initialize j = 0
step-vii)append character at j in s string to the string builder
step-viii)call the print function passing N,i+1, hashmap and str as parameters
step-ix)from string builder delete chatacter present at last and increment j by one value
step-x) repeat steps vii, viii and ix till j is less than length of string s

Time Complexity: O(n)
Space Complexity: O(n)


Note :

Let us know if you can come up with a better approach, mail us at support@theinquisitive.in Your approach will be reviewed and posted with credits to you.

oops

Login to see Solution