Challenge: nth In-Order

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

Problem

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

Input

An integer index.

Output

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

Sample input

index = 5

Sample output

10

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

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