Solution Review: nth Pre-Order
Let’s go through the detailed solution review of the challenge given in the previous lesson.
We'll cover the following
Solution
We keep track of our index in a counter. Because we want to print the node that is at the index in pre-order traversal, we’ll increment the counter as soon as we find a non-empty node. When the counter becomes equal to the index, we’ll print the value and return the pre-order index node.
Solution code
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.