

You have been given an array/list ‘TREE’ having ‘N’ unique integers. You need to make a maximum binary tree recursively from ‘TREE’ using the following conditions:
1. Create a root of the maximum binary tree whose value is the maximum value present in the ‘TREE’.
2. Recursively build the left subtree on the subarray prefix to the left of the maximum value.
3. Recursively build the right subtree on the subarray suffix to the right of the maximum value.
For example:
For ‘TREE’ = [6, 1, 8, 2, 5],see the maximum binary tree in the below picture for reference:

As we can see the root of the maximum binary tree as shown in the picture is ‘8’ which is the maximum value in the ‘TREE’. The left subtree contains all the values which are present in the left of 8 in ‘TREE’ and the right subtree contains all the values which are present in the right of ‘8’ in ‘TREE’. Similarly, the maximum value in the left subarray of 8 is 6 so 6 becomes the root of the left subtree, 5 is the maximum value in the right subarray of the 8 so 5 becomes the root of the right subarray, and so on.
The first line of input contains an integer 'T' representing the number of test cases. Then the test cases follow.
The first line of each test case contains an integer ‘N’ representing the number of elements in the ‘TREE’.
The second line of each test case contains ‘N’ space separated integers denoting the values of ‘TREE’.
Output Format :
For each test case, print the level order traversal of the maximum binary tree formed using the array/list ‘TREE’.
The output for each test case is printed in a separate line.
Note:
You are not required to print the expected output; it has already been taken care of, Just implement the function.
1 <= T <= 100
1 <= N <= 10 ^ 4
1 <= TREE[i] <= 10 ^ 4
Time limit: 1 second
2
2
1 5
3
8 10 2
5 1
10 8 2
For the first test case :
See the picture below for the output reference:

For the second test case :
See the picture below for the output reference:

2
1
8
5
12 3 15 1 11
8
15 12 11 3 1
Try to use recursion in this problem.
This approach aims to find the maximum element in ‘TREE’ and make it the root of the current binary tree. For the left and right subtree, we use the same approach using the left and right subarray, respectively.
We use the function ‘CONSTRUCT_MAX_TREE’ with three arguments ‘TREE’, ‘l’ and ‘r’, which will return the root of the maximum binary tree consisting of numbers within the indices ‘l’ and ‘r’ of the ‘TREE’.
Here is the complete algorithm:
O(N ^ 2), where ‘N’ represents the number of elements in the array/list ‘TREE’.
The function ‘CONSTRUCT_MAX_TREE’ is called ‘N’ times. At each level of the recursive tree, we traverse over all the ‘N’ elements to find the maximum element. So in the worst case, the depth of the recursive tree can grow upto ‘N’, which happens in the case of a sorted ‘TREE’. So the overall time complexity will be O(N ^ 2).
O(N), where N represents the number of elements in the array/list ‘TREE’.
Because the size of the recursion tree can grow upto ‘N’ in the worst case when ‘TREE’ will be sorted. Hence the overall time complexity will be O(N).