

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 ‘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’.
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.
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
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: