


Given a linked list containing N nodes where each node is associated with a certain value. The list is the representation of the level order traversal of a binary tree, you need to construct a complete binary tree from the given list and return its root.
Note1. A complete binary tree is a binary tree in which every level, except possibly the last, is completely filled, and all nodes at the last level are as far left as possible.
2. All the node values are positive.
3. The size of the linked list is greater than 1.
4. The end of the linked list is represented by -1.
The first line of the input contains an integer T denoting the number of test cases.
The first and the only line of each test case contains the values of nodes of the linked list L, which is to be converted into the complete binary tree.
Output Format:
Print the inorder traversal of the created binary tree.
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 50
1 <= N <= 10^4
Time Limit: 1sec
1
1 2 3 4 -1
4 2 1 3
The given linked list is :
After processing the level order input, we get the tree as:

Hence the inorder input of the tree is 4 2 1 3
1
10 12 15 25 30 36 -1
25 12 30 10 36 15
The given linked list is :

After converting the linked list into tree, we get:

Hence the inorder traversal of the tree is 25 12 30 10 36 15
Use the definition of level order traversal and complete binary tree.
O(N), where N is the number of nodes in the linked list.
O(N), where N is the number of nodes in the linked list.