I have attended an interview couple of days back, to me its a toughest interview I have ever attended. Its a client interview and my employer arranged for it, such interviews are supposed to be a formality but this one is no easy.
The interview was for one hour and I was asked only 2 programming questions! Here they are:
1. How do you find out if a binary tree is a valid binary tree (My answer was to check if the left < root < right node. I wrote a recursive program to check this.)
2. Do a pre-order traversal of binary tree *without using recursion* (I struggled a lot for this! I got the clue from interviewer that we can use stacks. After a lot of inputs, I could write C code. I also had to do lot of modifications after writing the code so that it works correctly.) Here is the code I wrote:
The interview is over after I wrote this code! This interview is actually a telephonic interview and the interviewer asked me to sit with a computer with net connection. She then asked me to send the code by mail. but, my computer is connected to a firewall which blocks all the mail sites and there is no email configured (since its a meeting room computer). I suggested that I can use http://cl1p.net. This site actually is like a clipboard website where I can paste the text and save it for later use. My suggestion worked very well, as I could just type in the code there and she was able to see it on her machine. This was very suitable for my interview.
void preorder(node* root)
{
if(root==NULL) return;
stack *temp;
node *trav = root;
printf("%d", trav->value);
while (trav!=null)
{
if(trav->right!=null)
temp->push(trav->right);
if (trav->left != null)
temp->push(trav->left);
printf("%d", trav->value);
trav = trav->left;
trav = temp->pop();
}
}
Overall, its a different experience as my 8 yrs experience in software is tested based on just two programming questions!
0 comments:
Post a Comment