## 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.
Comment hidden because of low score. Click to expand.
0

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?

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

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

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

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

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

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

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

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

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?

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

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

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.

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

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

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

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.``````

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.

### 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.