Convert Min Heap to Max Heap Problem Statement

Given an array representation of a min-heap of size 'n', your task is to convert this array into a max-heap.

Input:

The first line of input contains an integer ‘T’ denoting the number of test cases.
The next 2*T lines represent test cases.
The first line contains a single integer ‘n’ denoting the size of the array.
The next line contains ‘n’ space-separated integers denoting the min-heap.

Output:

Return any possible max-heap for the given input min-heap.
Output for each query is printed in a separate line.

Example:

Input:
min-heap = [1,2,3,6,7,8]
Output:
max-heap = [8,7,3,6,2,1]

Constraints:

  • 1 <= T <= 10
  • 1 <= n <= 5000
  • 1 <= arr[i] <= 105
  • Time Limit: 1 sec

Note:

The output max-heap will be checked from the given function: if the output array is a max-heap, it will return true; otherwise, it will return false.

AnswerBot
4mo

Convert a given min-heap array into a max-heap array.

  • Iterate through the given min-heap array and build a max-heap array by swapping elements.

  • Start from the last non-leaf node and heapify down to main...read more

Help your peers!
Select
Add answer anonymously...

UBS Business Technology Analyst interview questions & answers

A Business Technology Analyst was asked Q. What is the difference between function overloading and overriding?
A Business Technology Analyst was asked Q. What is polymorphism?
A Business Technology Analyst was asked Q. How does function overloading work?

Popular interview questions of Business Technology Analyst

A Business Technology Analyst was asked Q1. What is the difference between function overloading and overriding?
A Business Technology Analyst was asked Q2. What is polymorphism?
A Business Technology Analyst was asked Q3. How does function overloading work?
UBS Business Technology Analyst Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits