Solution Review: nth In-Order

Let’s go through the detailed solution review of the challenge given in the previous lesson.

Solution

We’ll make a counter to keep track of our index. Because we want to print the node that is at the nthn^{​th} index in in-order traversal, we’ll increment after we traverse the left child but before we traverse the right child. When the counter becomes equal to the index, we’ll print the value and return the nthn^{​th} in-order index node.

Solution code

Get hands-on with 1400+ tech skills courses.