Challenge 1: Convert Max-Heap to Min-Heap

Given a max heap, convert it into a min heap.

Problem statement

Implement a function convertMax(List<int> maxHeap), which will convert a binary max heap into a binary min heap. Where maxHeap is a vector, which is given in the maxHeap form, i.e., the parent is greater than its children.

Input

This is a max heap.

Output

It returns the converted list in string format.

Sample input

maxHeap = {9,4,7,1,-2,6,5}

Sample output

result = "-2,1,5,9,4,6,7"

Take a look at the following diagram:

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.