Comments (2)

Reputation -5

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.

Given T, find:

- lima.gus December 29, 20151. Let array A be the in-order traversal of T.left

2. Let array B be the in-order traversal of T.right

Both A and B can be produced in one pass - make sure to add a marker for whenever you see a null on one side but not the other - this guarantees A and B will have the same size, which will come in handy in further steps.

3. Let array C be the pre-order traversal of T.left

4. Let array D be the pre-order traversal of T.right

Likewise, both C and D can be produced in one pass - make sure to add a marker for whenever you see a null on one side but not the other - this guarantees C and D will have the same size.

5. Check if A has a sequence which is also in B (since A and B are the same size, this can be done in O(n) )

6. Check if C has a sequence which is also in D (since C and D are the same size, this can be done in O(n) )

7. If both 5 and 6 are true, continue, otherwise we can return false

8. If the sequences found in 5 and 6 are a permutation of each other (can be done in O(n)), then return true.