the same question i have asked in microsoft interview. (if it is the same
:P)
for 12 perutation are (ad, ae, af, bd, be, bf, cd, ce ,cf);
i have given them 3 solution(recusrsive, stack based) and the last one what
they wanted.
take a tertiary number(n) = 3^(number of digits) in case of 12 it is equals
to 2;
i m solving the save problem. assuming on every key there are only 2
alphabets.
char c[][2] = {ab , cd, ......};
char n[] = 2156169 (number is pressed);
so k = 7;
for (i = 0; i < (1<<k); i++){
string s = "";
for (j = 0; j < k; j++){
s += c[n[j]][i & (1<<j)]
}
print(s);
}
same logic u can use for tertiary too.
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.