Challenge: nth Pre-order

Let’s print the value present in the nth node when traversing a tree in pre-order.


Given a binary tree, print the value of nodes that will be at the nthn^{th} index when the tree is traversed in pre-order.


An integer index.


Display the value of the node at the given index in pre-order traversal.

Sample input

index = 5

Sample output


Let’s look at the illustration below to better understand the problem.

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