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.
I believe storing the pre-order and in-order sequence is the optimal solution: it takes roughly 2*n bytes to store, where n is the number of nodes in the tree, and it removes the complication in dealing with unbalanced or incomplete trees. Here's an example:
- weicool January 14, 2008Say we're given the following sequences (completely arbitrary):
Pre-order: abdecf
In-order: dbeafc
To reconstruct the tree, we'd read these two lines into two arrays. In a recursive function, we examine the first element of the pre-order array, which is obviously the root node of the current tree we're building. We locate its position in the in-order array, in this case, array index 3. As a result, we can divide the in-order array into two parts: the left branch (dbe) and the right branch (fc). Knowing that, we also know the "length" of those two branches, which we can use to extract bde and cf from the pre-order array. To finish it off, we set the left branch to be the result of calling the function recursively on pre-order bde, in-order dbe and the right branch to be the result of calling the function recursively on pre-order cf, in-order fc.
Try it out -- it works. :D