Flipkart Interview Question for Software Engineer / Developers


Country: India
Interview Type: Phone Interview




Comment hidden because of low score. Click to expand.
0
of 2 vote
{{{If max_height(node) is given : Let N be the given node and Let it be at level 'X'. 1. Keep three pointers L,Curr,R and let Curr=root, L = NULL, R=NULL. Let Curr_level = 0. 2. If (Curr == N) Print L and R. END; 3. If N lies in LEFT sub-tree of Curr: L = L->right or L->left or NULL; (depending on whether the respective subtree max_height(Node) > (X - Curr_level)) R = Curr->Right or R->left or R->right or NULL; (depending on whether the respective subtree max_height(Node) > (X - Curr_level)) Curr = Curr->left; 4. ElseIf N lies in RIGHT sub-tree of Curr: R = R->left or R->right or NULL; (depending on whether the respective subtree max_height(Node) > (X - Curr_level)) L = Curr->left or L->right or L->left or NULL; (depending on whether the respective subtree max_height(Node) > (X - Curr_level)) Curr = Curr->right; 5. Curr_level++; goto Step 2. - novice October 16, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

at step 3, you are assuming that you KNOW something that has to be discovered: whether N is in the left of right subtree. I don't see any way you can know - where'd you get that?

- wiseguy October 28, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I guess this would work for a complete tree(i.e. tree with either two or none children). It certainly didn't work for the tree that I applied it for. BTW, please be a little more clear in your pseudo-code. I cudn't understand the "depending" stuff at all

- Amar February 14, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

hey u never reached the siblings of the given node...
its asked to find the left and right neighbours u are increasing the level but they will be present at same level
right??
please corret if i hav understood it wrongly

- shreyans June 25, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

k...got u i was thikng that only the tree after level x would be given..
this one is a rather casual one

- shreyans June 25, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

The formatting is so bad. Its difficult to comprehend things easily. @novice, i guess this is not a paragraph writing.

- Anup Rungta March 14, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can u explain the problem a bit more clearly, From what I understood, it is asked that we need to find the siblings(only left and right) for the given node.

The questions I have are

1. Are you given a standard binary tree with just left and right pointers?
2. If so, are you allowed pre-process the tree before you can actually find the left and right siblings?

- ashok.koyi November 03, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

can anyone here explain that what is max height node here??

- Anonymous February 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 4 vote

Find the depth of the given node.Then print all the nodes with the same depth.

- Guddu Sharma May 04, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

You don't have access to the root so this would require you to find the root first.

- Daniel November 17, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 2 vote

using levelNumber as the hash, store the nodes.... and while traversal, also have the level of the given node by comparision

- Anonymous May 16, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1) Find the depth of the node, say h
    2) Now, take a pointer nodePtr. Start doing DFS upto that level. Initialize nodePtr will NULL.
    3) We get a node, Nh at level h, store it into nodePtr
    4) get another node on level h, but this is not given node, then store this new node in nodePtr.
    5) While repeating step 4, we will come to a point where we have a node N which is stored in nodePtr and just next node in the DFS on that hight h is given node, print this nodePtr node. This is left node of given node.
    6) in next iteration, we will get right node of given node.

- SK July 03, 2013 | 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