Challenge: Convert Max-Heap to Min-Heap
Given a Max-Heap, convert it into a Min-Heap. A solution is placed in the "solution" section for your help, but we would suggest you solve it on your own first.
We'll cover the following
Problem Statement #
Implement a function convertMax(vector<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.
Output #
Returns 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"
Have a look at the following diagram
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.