Reverse Level Order Traversal
Submissions: 24935   Accuracy:


  Difficulty: Easy   Marks: 2

Given below is a tree. The task is to print the Reverse Level Order Traversal of the given tree. You will be given a function reversePrint(), which accepts root of the tree as argument.


The first line of input contains T, denoting the number of testcases. Each testcase contains number of edges. The second line contains number of edges+1 data of nodes of tree separated by space.

For each testcase in new line, print the reverse level order traversal of tree separated by space.

User task:
Since this is a functional problem you don't have to worry about input, you just have to complete the function reversePrint().

1 <= T <= 30
1 <= Number of edges <= 3*103
1 <= Data of a node <= 3*103


1 2 R 1 3 L
10 20 L 10 30 R 20 40 L 20 60 R

3 2 1
40 60 20 30 10

Testcase 1:
There are total 3 nodes of tree.

Reverse level order traversal of tree is: 3 2 1.

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Amit Khandelwal
Author: Shubham Joshi 1

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use, generate link and share the link here.

to report an issue on this page.