Given a Linked List Representation of Complete Binary Tree. The task is to construct the Binary tree.
Note : The complete binary tree is represented as a linked list in a way where if root node is stored at position i, its left, and right children are stored at position 2*i+1, 2*i+2 respectively.
Input:
First line of input contains number of testcases T. For each testcase, first line of input contains length of linked list and next line contains linked list elements.
Output:
Output of each test case will be the level order traversal of the the constructed binary tree.
User Task:
The task is to complete the function convert() which takes head of linked list and root of the tree as the reference. The driver code prints the level order.
Constraints:
1 <= T <= 100
1 <= N <= 103
1 <= Ki <= 103
Example(To be used only for expected output ) :
Input
2
5
1 2 3 4 5
5
5 4 3 2 1
Output:
1 2 3 4 5
5 4 3 2 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.
preparecodinginterview_dot_com | 190 |
__murugan__ | 173 |
manvimahajan20 | 140 |
xiaoyan_yunche | 139 |
ShameekAgarwal | 116 |
preparecodinginterview_dot_com | 190 |
__murugan__ | 173 |
manvimahajan20 | 166 |
SoumyaKaushik | 146 |
arpit_anshuman | 140 |
blackshadows | 5331 |
Ibrahim Nash | 5219 |
akhayrutdinov | 5111 |
mb1973 | 4929 |
Quandray | 4567 |