## amit.h1b

BAN USERHere is my solution

mynode *closestAncestor(mynode* root, mynode* p, mynode* q)

{

mynode *l, *r, *tmp;

if(root == NULL)

{

return(NULL);

}

if(root->left==p || root->right==p || root->left==q || root->right==q)

{

return(root);

}

else

{

l = closestAncestor(root->left, p, q);

r = closestAncestor(root->right, p, q);

if(l!=NULL && r!=NULL)

{

return(root);

}

else

{

tmp = (l!=NULL) ? l : r;

return(tmp);

}

}

}

here comes my colution

P1= 105

P2= p1*3

P3= p1*5

P4= p1*7

P5= p1*3*3 = p2*3

P6= p1*3*5 = p3*3

P7= p1*3*7 = p4*3

p8= p5*3

P9= p5*5 = (P1*3*3)*5 =(p1*3*5)*3= p6*3

p10=P5*7 = p7*3

This leads to recusion

p(k) = p(k-3)*3 for k > 4

int findkth(int k)

{

if (k == 1)

{

retrun 3*5*7;

}else if( k == 2)

{

return 3*5*7*3;

}

else if( k == 3)

{

return 3*5*7*5;

}

else if (k == 4)

return 3*5*7*7;

else if

findkth(k-3)*3;

}

Rep**pamelajoung**, Dev Lead at Absolute Softech LtdI have worked as a wedding photographer for the past two years, first as a photographerâ€™s assistant and then ...

**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

Open Chat in New Window

What was your answer ?

- amit.h1b August 27, 2008