Leaf Nodes and Height

0

0 votes
Easy
Problem

Use the tree constructed in question 1 to print all the leaf nodes in inorder fashion, also calculate the height of the tree. Input format and constraints are same as question 1.

Output Format:

In first line print the leaf nodes in inorder fashion.

In second line print the height of the tree.

Sample Input
10
6 3 2 5 4 1 8 7 9 10
Sample Output
1 4 7 10 
4
Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

For given input constructed tree will look like the following:

                     6
                    / \
                   3   8
                 /  \   /  \
                2  5 7   9
               /    /         \
              1    4         10 
Hence leaf nodes in inorder fashion are 1 4 7 10.

And height of tree is 4.

Editor Image

?