Merge Two Binary Max Heaps

easy
1. You are given two arrays of N and M elements. 2. These two arrays represent two binary max heaps. 3. You have to merge the elements of both the arrays such that the resulting array is also a max heap. Note: If the two arrays contain common elements, the resultant array should contain both the duplicate elements. 4. For example, Input : a = {10, 5, 6, 2}, b = {12, 7, 9} Output : {12, 10, 9, 2, 5, 7, 6} a => 10 b => 12 / / / / 5 6 7 9 / / 2 output => 12 / / 10 9 / / 2 5 7 6 5. display is a utility function, feel free to use it for debugging purposes. 6. main takes input from the users and creates the arrays. 7. This is a functional problem. 8. You have to complete the solve function. It takes as input both the arrays representing binary max heaps and their sizes. It should return the merged binary max heap array. 9. Don't change the code of main and display and other functions defined.

Input Format

First line takes input N, the length of the first array. Second line takes input N space separated numbers representing the elements of the first array. Third line takes input M, the length of the second array. Fourth line takes input M space separated numbers representing the elements of the second array. Input is handled for you.

Output Format

First line: Merged Correctly Second line: The resultant array in sorted order: Third line: The elements of resultant max heap array in sorted order. If the merging is not correct, the output is "Wrong Answer". Output is handled for you.

Constraints

1 <= N, M <= 1000

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
4
10 5 6 2
3
12 7 9
Output
Merged Correctly
The resultant array in sorted order:
2 5 6 7 9 10 12
Previous
Split Array Into Consecutive Subequences
Next
Sort The String In Descending Order

Related Questions