is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.
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.
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.
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.
If the given tree is a BST then the second solution posted above is right. But since it has just been provided as a Binary tree i dont think we can use that solution.
- rathi December 04, 2007@Laks: Inorder traversal is just a method of printing out nodes, since we can assume the Binary tree to be ordered in any particular manner.. i dont think simply doing a inorder traversal would give the result.
A brute force approach i can think of ;)
- Do a traversal and store the values of all nodes in an array - O(n)
- Find the next higher element by making a one pass through the array-
O(n)
Val : = value of node given to us .. whose higher noder we have to find
Big : value of the next bigger node set to 0
for( i from 1 to n)
{
if (array[i] > Val)
{
if(array[i] < Big)
Big = array[i]
}
}
- Traverse the tree looking for the node having the value of Big and return O(n)
Maybe the whole thing can be accomplished by 2 Traversals too minus the temp array
Do a traversal and find value of Big
Do a traversal and get node corresponding to Big