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.
Since this is listed as a C interview question (not C++) I did an answer in C99.
Most of the code is test cases and linked-list handling (for the paths). The real solution is the 3 routines at the beginning
The algorithm is simple:
(1) Find a pointer to the right sibling O(n) worst case: chosen node is leftmost child on lowest level of full binary tree that has no other children at our node's depth.
(2) Create a path between the initial node and the right sibling by following their parent pointers up until they reach a common ancestor. O(path length)
Finding the right sibling is also a simple recursive routine:
If this is the left child and the parent has a right child, that is this node's right sibling. Otherwise, keep finding right siblings of the parent and choose the leftmost of their children. If none of the parent's right siblings has children, there is no right sibling for this node.
- Computron June 16, 2014