TITLE:-Return Keypad Code
Return empty string for numbers 0 and 1.
Note : 1. The order of strings are not important.
Integer n
All possible strings in different lines
Constraints :
1 <= n <= 10^6
23
Sample Output:
ad
ae
af
bd
be
bf
cd
ce
cf
SOLUTION:-
#include <iostream>
#include <string>
using namespace std;
int keypad(int num, string output[]){
/* Insert all the possible combinations of the integer number into the output string array. You do not need to
print anything, just return the number of strings inserted into the array.
*/
if(num <0)
return -1;
if(num==0||num==1)
{
output[0]="";
return 1;
}
int smallnum=num/10;
int renum=num%10;
int smallcount=keypad(smallnum,output);
int vo;
string s[]={"abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
if(renum==7||renum==9)
vo=4;
else
vo=3;
int j=0;
int c=0;
string output1[10000];
while(j<vo)
{
for(int i=0;i<smallcount;i++)
{
output1[c]=output[i] +s[renum-2][j];
c++;
}
j++;
}
for(int i=0;i<c;i++)
{
output[i]=output1[i];
}
return vo*smallcount;
}