Reverse Level Order Traversal

Level MEDIUM

Given a binary tree.Traverse the tree in the manner of reverse level order

Example:

                       5
                      / \  
                     6   2  
                        / \
                       2   3
                      / \
                     9   7

    Reverse level order traversal for this tree is:
    7 9 3 2 2 6 5
Input format :
Line 1 :  Elements in level order form (separated by space)
(If any node does not have left or right child, take -1 in its place)
Output Format :
Print Reverse level order traversal 
Constraints :

1 <= N <= 10^5

Input:
5 6 2 2 3 -1 -1 9 7 -1 -1 -1 -1
Output :
7 9 3 2 2 6 5

Comments

Popular posts from this blog

MySQL Multi Source Master Slave Replication using GTID

Access and modify all the resources of our Wiki.js using WikiJS API

How to pass parameters in webhook?