Yahoo Interview Question for Software Engineer / Developers






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

int FindDepth(Node *node)
{
int leftDepth, rightDepth;
if (node == NULL)
return 0;

else{

leftDepth = FindDepth(node->left);
rightDepth = FindDepth(node->right);

if (leftDepth > rightDepth)
return (leftDepth+1);
else
return (rightDepth+1);

}

}

- dronzer709 June 21, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

It can be done by a DF search with less memory.

- memo June 21, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Please could you explain your approach

- Anonymous August 12, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Wud like to make one point: whether its above recursive approach or bfs or dfs to find the depth of tree, it all run in O(n) time complexity, where n is the number of nodes in tree, as each node is required to be visited before answering the depth of tree.

About memory consumption, it varies based on the type of tree. If tree has more depth than breadth, dfs will consume more memory otherwise bfs will consume more memory.

- wolverine December 02, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Isnt it tht Yahoo started asking bit basic textual questions

- anshulzunke September 15, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Since we require to optimize memory used , so I think iterative solution would be better than recursive.

Iterative approach:-
Solution is similar to iterative level-order-traversal of a tree using a queue .
For each level increment the counter.
Final value of the counter would be the required answer

- koolkeshaw July 13, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I completely agree with u Keshaw. Iterative is better if interviewer is asking for memory optimization

- anshul July 13, 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