## Amazon Interview Question for Development Support Engineers

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

Find the height from the root node to the leaf nodes and return the leaf node which has the min. height.

Please correct me if i am wrong.....

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

what if we do breadth first traversal of the tree, ending the traversal at the first leaf that we encounter?

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

makes sense to me

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

How do you keep track of the depth with BFS?

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

Correction: We don need the depth. Just the leaf node! :)

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

@m - brilliant !

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

int lowleaf(node *root)
{
if(root==NULL) return 1;
else
return 1+min(lowleaf(root->left),lowleaf(root->right));
}
//min returns min of 2 values

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

correction:
if(root==NULL) return 0;

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

You are returning the length,not the leaf node. :(

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

int *queue;
insert_into_Q(root);
int flag=0;
int i=1;
while(1)
{
int k=0;
int j=0;
while(j<i)
{
node=extract_from_Q();
if(node->left==NULL&&node->right==NULL)
{
print node->value;
flag=1;
}
insert_into_Q(node->left);
k++;
insert_into_Q(node->right);
k++;

j++;
}
if(flag)
break;
i+=k;
}

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

last command should be i=k;

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

Any comments are welcome!

void FindBottomMostLeaf(node* root, int level)
{
node* p = root;

if(!p)
{
return;
}

if(p)
{
if(p->left == NULL && p->right == NULL)
{
{
}
else
{
{
{
FreeLNode();
}
}
}
}
else
{
level++;
FindBottomMostLeaf(p->left, level);
FindBottomMostLeaf(p->right, level);
}
}

}

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

Two ways to solve the sum:
1)Using BFS.
While doing BFS the first node that is encountered to be a leaf is the answer.
Node mod_bfs(Node root)
{
if(root==null) return null;
While(!l.isEmpty())
{
int size=l.size();
for(int i =0;i<size;i++)
{
Node u=l.removeFirst();
if(u.leftchild==null and u.rightchild==null) return u;
if(u.leftchild)
if(u.rightchild)
}
}

}
2)Find min depth of tree using
int Find-Depth(Node root,int level)
{
if(root==Null)return level;
level=level+1;
return min(Find-Depth(root.left,level),Find-Depth(root.right,level));
}

Then just traverse the tree using inorder or postorder or preorder and find the node that is a leaf and at level=level returned by above function.

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.