


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. Return the max-heap array representation.
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]

The first line contains a single integer ‘N’ denoting the size of the array.
The next line contains ‘N’ space-separated integers denoting the array representation of min-heap.
Output Format
There can be many possible max-heaps. Return any possible max-heap for given input min-heap.
6
1 2 3 4 5 6
true
The min-heap representation is:-

One of the possible max heap for a given min-heap
is [6,5,4,2,3,1]

7
3 5 6 7 9 12 7
true
1 <= ’N’ <= 5000
1 <= arr[ i ] <= 10^5
where, 'N' denotes the size of the array and arr[i] denotes the elements of the input array.
Time Limit : 1 sec
Sort the array in descending order.
The main idea is that when an array is sorted in descending order it becomes max heap as for every ‘i’ from i=0 to n/2 it is greater than equal to arr[2*i+1] and arr[2*i+2].
O(n*log(n)), where n is the size of the array.
Sorting an array takes O(n*log(n)) time complexity.
O(1)
We are using constant space to solve this.