Convert Min Heap To Max Heap

You are given an array of size ‘n’ which is an array representation of min-heap. You need to convert this min-heap array representation to a max-heap array representation.

For Example- Corresponding to given min heap :-[1,2,3,6,7,8]

It can be converted to the following max heap:[8,7,3,6,2,1]

Input Format:
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 Format
There can be many possible max-heaps. Return any possible max-heap for given input min-heap.

Output for each query is printed in a separate line.

Note

The output max-heap will be checked from the given function:-

If the output array is max-heap it will return true else it will return false.

Constraints:
1 <= ’T' <= 10
1 <= ’n’ <= 5000
1 <= arr[ i ] <= 10^5

where 'T' denotes the number of test cases, 'n' denotes the size of the array and arr[i] denotes the elements of the input array.

Time Limit : 1 sec
Be the first one to answer
Add answer anonymously...
UBS Business Technology Analyst 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
Get AmbitionBox app

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