Interview Question


Country: -




Comment hidden because of low score. Click to expand.
0
of 0 vote

{int in =8;
int t=0;
while(in>=1){
in =in>>1;
t++;
}
t gives value. even this looping is not allowed?

- Anonymous October 18, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

posted above code in wrong place..

- Anonymous October 18, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

which company asked this question ???? or is this ur homework problem??

- Anonymous October 23, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

this questions is asked by flipkart

- abc October 24, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This can be solve by storing the ancestors path to the node. Then we can Print the neighbours accordingly.
Algo-> Store the ancestoral path in an array or say vector.
Now from the root start printing the nodes which are neighbours to this node
Here is a working code for the same

void PrintNodes(node* temp,node* Node,vector<node*>v,int n){//To Print the Neighbour //Nodes
if(!temp) return;
if(n==0){
if(temp==Node) return;
if(temp) cout<<temp->data<<"->";
return;
}
PrintNodes(temp->left,Node,v,n-1);
PrintNodes(temp->right,Node,v,n-1);
return;
}
bool StoreNodePath(node* root,node* Node,vector<node*>&v){//Function for storing //the Ancestors path
if(!root|| !Node) return false;
if(root==Node) return true;
if(StoreNodePath(root->left,Node,v) || StoreNodePath(root->right,Node,v)){
v.push_back(root);
return true;
}
return false;
}
void printNeighbours(struct node *root, node* node){ //Initial Call to this Function
/* base cases */
if(node==root) return;
if ( root == NULL )
return ;
int n;
vector<struct node*>v;
bool found = StoreNodePath(root,node,v);
if(!found) return;
else{
n=v.size();
struct node* temp=v.back();
PrintNodes(temp,node,v,n);
}
}

- Ankur December 07, 2011 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More