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

- sai October 13, 2008 | Flag Reply
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?

- m October 13, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

makes sense to me

- chinni October 14, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

How do you keep track of the depth with BFS?

- Anonymous October 20, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

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

- Anonymous October 20, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@m - brilliant !

- Anonymous January 15, 2010 | Flag
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

- psp.reachable@gmail.com October 15, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

- psp.reachable@gmail.com October 15, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

- Ashok October 16, 2008 | Flag Reply
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;
}

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

last command should be i=k;

- Anonymous October 21, 2008 | Flag Reply
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)
{
if(!head)
{
AddLNode(level, p);
}
else
{
if(head->level <= level)
{
if(head->level < level)
{
if(head)
FreeLNode();
}
AddLNode(level, p);
}
}
}
else
{
level++;
FindBottomMostLeaf(p->left, level);
FindBottomMostLeaf(p->right, level);
}
}

}

- dullboy April 28, 2010 | Flag Reply
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;
LinkedList<Node> l= new LinkedList<Node>();
l.add(root);
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)
l.add(u.leftchild);
if(u.rightchild)
l.add(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.

- Tejas February 23, 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