Merge two binary Max heaps
Submissions: 2676   Accuracy:

26.01%

  Difficulty: Easy   Marks: 2

Given two binary max heaps as arrays, merge the given heaps, after merging the two arrays.
The task is very simple to merge the two arrays firstly keep all the elements of first array than elements second array, than apply the merge operation of heaps.

Input:
First line consists of T test cases. First line of every test case consists of 2 integers N and M, denoting the number elements of two arrays (MAX HEAP). Second and third line of every test cases consists of elements of 2 Heaps respectively.

Output:
Single line output, print the merged max heap.

Constraints:
1<=T<=100
1<=N,M<=100

Example:
Input:

1
4 3
10 5 6 2
12 7 9
Output:
12 10 9 2 5 7 6 

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Saksham Raj Seth
Author: support3


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.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.