Print Tree in Bottom up Order

Given a Binary Tree, traverse the tree and print the tree from bottom up order. That means, you need to print the tree in level order manner but from the bottom. Last level should be printed first, then second last level and so on.

Note : Print the nodes separated by space.

alt

Input format :

Elements in level order form (separated by space)

(If any node does not have left or right child, take -1 in its place)

For eg. In above Binary tree, you need to take -1 for left and right children of 10, 2, 2 & 13

Sample Input :
5 6 10 2 3 -1 -1 -1 -1 2 13 -1 -1 -1 -1
Sample Output :
2 13 2 3 6 10 5

Login to submit your solution

Fb dab53a1a64929320dc7425896aa73fd9e5512b6ab52e414ff5f3ebb5cecc73eb

Share Problem