@sravan,
What i meant was get the jth digit in the representation of i to the base
NUM_PER_DIGIT. ie 3rd digit of (2137)8 which is 2.. 7 is the 0th digit, 3
being 1st digit, 1 being 2nd digit and 2 being 3rd digit.Here 2137 is a base
8 representation.
Thanks,
Immanuel
On Tue, May 24, 2011 at 6:37
@Immanuel:
In the iteretive approach, can you tell me what you meant by this function.
A code is not required, but, how are we going to calculate? the method name
is little confusing.
The recursive is good.. but.. I'm looking at the iterative approach.
---> getJthDigitinItotheBaseNumPerDigit(N
@Anuj, true.This will optimise the solution by reducing the amount of stack
space used for recursion.
NUM_PER_DIGIT = 3
char c[][NUM_PER_DIGIT] = {"abc","def",...};
char n[] = 2156169 (number is pressed);
int k=7;
char * s = (char *) malloc(sizeof(char) * k);
void printAllCombinations (int k, c
Immanuel,
We can keep c and n arrays as global variable as they are not part of state
of the recursion.
Anuj Agarwal
Engineering is the art of making what you want from things you can get.
On Mon, May 23, 2011 at 10:04 PM, immanuel kingston <
kingston.imman...@gmail.com> wrote:
> small correcti
small correction
On Mon, May 23, 2011 at 9:46 PM, immanuel kingston <
kingston.imman...@gmail.com> wrote:
> A Recursive soln:
>
>
> NUM_PER_DIGIT = 3
> char c[][NUM_PER_DIGIT] = {"abc","def",...};
>
> char n[] = 2156169 (number is pressed);
> int k=7;
> char * s = (char *) malloc(sizeof(char) * k
A Recursive soln:
NUM_PER_DIGIT = 3
char c[][NUM_PER_DIGIT] = {"abc","def",...};
char n[] = 2156169 (number is pressed);
int k=7;
char * s = (char *) malloc(sizeof(char) * k);
void printAllCombinations (char c[][], char n[], int k, char *s, int count)
{
if (count >= k - 1) {
s[k] = '
Extending the above soln:
NUM_PER_DIGIT = 3
char c[][NUM_PER_DIGIT] = {"abc","def",...};
char n[] = 2156169 (number is pressed);
int k=7;
for i <-- 0 to NUM_PER_DIGIT ^ k
String s="";
for j <-- 0 to k
int index = getJthDigitinItotheBaseNumPerDigit(NUM_PER_DIGIT,i,j);
// ie get 1s
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 e
I didn't get the question actually. I have copied the post(the
question). but i dont think for 12, 36 can be the answer. We have to
go for the permutation of the telephone number i guess after
substituting for each number the corresponding set of alphabets.
The question given is - "Given a telephon