

1. Each element in the array represents a node of the heap.
2. Element at index 0 represent the root of the heap.
3. If a node is represented by elements at index ‘i’ then its left and right child is represented by elements at indices ‘2*i + 1’ and ‘ 2*i + 2’ respectively.
Consider ‘ARR1’ = [10, 5, 6, 2] and ‘ARR2’ = [12, 7, 9].

The max-heap obtained by merging can be represented by array [12, 10, 9, 2, 5, 7, 6]
The first line of input contains an integer ‘T’ denoting the number of test cases.
The next ‘3*T’ lines represent the ‘T’ test cases.
The first line of each test case contains two space-separated integers ‘N’, and ‘M’ representing the size of the array ‘ARR1’ and ‘ARR2’ respectively.
The second line of each test case contains ‘N’ space-separated integers representing the array ‘ARR1’.
The third line of each test case contains ‘M’ space-separated integers representing the array ‘ARR2’.
For each test case, print a separate one line consisting of ‘N + M’ space-separated integers representing the Max-Heap obtained after merging.
You do not need to print anything, it has already been taken care of. Just implement the given function.
If the returned Heap is max-Heap of the given heaps then "Correct answer" will be printed else "Wrong answer" will be printed.
1 <= ‘T’ <= 50
1 <= ‘N’ <= 10^4
1 <= ‘M’ <= 10^4
1 <= ‘ARR1[i]’, ‘ARR2[i]’ <= 10^9
Time limit: 1 sec
In this approach first, we simply merged both arrays ‘ARR1’and ‘ARR2’ by first keeping all the elements of the ‘ARR1’ (without changing order) followed by the elements of array ‘ARR2’ (without changing order). Let ‘merged’ be the array obtained by merging ‘ARR1’and ‘ARR2’. We consider that ‘merged’ represents a complete binary tree, where the element at index ‘0’ is the root and for any index ‘i’ its left and right child nodes are at index ‘2*i + 1’ and ‘2*i + 2’ respectively. In order to convert it into Max-Heap, we need to use the Max-Heapify algorithm. We use the Max-Heapify algorithm to correct a max-heap if one of its nodes is misplaced.
The following is Max-Heapify Algorithm:-
Create a recursive function maxHeapify(Arr, i), where an array ‘ARR’ represents the heap (consider 0-based indexing) and ’i’ is the index to start at when heapifying down. In this function do the following.
Time taken by the Max-Heapify algorithm is O(H),. where ‘H’ is the height of node ‘i’.
We need to convert the array ‘merged’ of size ‘N+M’ in max-heap. It can be clearly seen that the complete binary tree represented by the array ‘merged’ does not follow the Max-Heap property. So, the idea is to heapify the complete binary tree formed from the array in reverse level order following a top-down approach. That is first max-heapify, the last node in level order traversal of the tree, then max-heapify the second last node, and so on.
We can observe that in the complete binary tree half of the nodes are leaf nodes and a single leaf node is a valid Max-Heap, Thus it is enough if we start applying max-heapify from the index ‘(N + M)/2’ to ‘0’, instead of ‘N + M’ in array ‘merged’.
Int[] mergeHeap(N, M, ARR1, ARR2)