Challenge: nth Pre-order
Let’s print the value present in the nth node when traversing a tree in pre-order.
We'll cover the following
Problem
Given a binary tree, print the value of nodes that will be at the index when the tree is traversed in pre-order.
Input
An integer index
.
Output
Display the value of the node at the given index
in pre-order traversal.
Sample input
index = 5
Sample output
9
Let’s look at the illustration below to better understand the problem.
Get hands-on with 1400+ tech skills courses.