Solution Review: nth Post-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 post-order traversal, we’ll increment after we traverse the left child and right child. When the counter becomes equal to the index, we’ll print the value and return the nthn^{​th} post-order index node.

Solution code

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.