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.

AnswerBot
2d

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

Help your peers!
Add answer anonymously...
Noon Academy Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter