Merge Two Binary Max Heaps Problem Statement
You are given two integer arrays Arr1
and Arr2
of sizes N
and M
respectively. Both Arr1
and Arr2
represent Max-Heaps. Your task is to merge these two arrays while retaining their respective order, and then construct the Max-Heap obtained by merging them.
Input:
The input will consist of:
- An integer T
that denotes the number of test cases.
- For each test case, the following lines are provided:
- Two space-separated integers N
and M
representing the sizes of arrays Arr1
and Arr2
respectively.
- N space-separated integers representing the elements of Arr1
.
- M space-separated integers representing the elements of Arr2
.
Output:
For each test case, print a single line containing N + M
space-separated integers representing the Max-Heap obtained after merging.
Example:
Input:
1
4 3
10 5 6 2
12 7 9
Output:
12 10 9 2 5 7 6
Constraints:
1 <= T <= 50
1 <= N <= 10^4
1 <= M <= 10^4
1 <= Arr1[i], Arr2[i] <= 10^9
- Time limit:
1 sec
Note:
You do not need to print any output. Simply implement the function. If the returned heap is a valid max-heap for the given heaps, "Correct answer" will be displayed; otherwise, "Wrong answer" will be shown.
Merge two Max-Heap arrays while retaining order and construct the merged Max-Heap.
Merge the two arrays while maintaining their respective order.
Construct the Max-Heap obtained after merging the arrays...read more
Top Noon Academy Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
Reviews
Interviews
Salaries
Users/Month