Convert Array to Min Heap Task

Given an array 'ARR' of integers with 'N' elements, you need to convert it into a min-binary heap.

A min-binary heap is a complete binary tree where each internal node's value is smaller than or equal to its children's value.

Example:

Input:
ARR = [3, 1, 6, 5, 2, 4]
Output:
Checker prints 1 if 'ARR' is a valid min-heap after modification, otherwise 0

Explanation:

Your task is to modify the array 'ARR' to satisfy the min-heap properties and test if the checker can verify it as a valid min-heap by returning 1.

  • The input follows a 0-based indexing system.
  • Ensure the left child of the i-th node is at (2*i + 1)-th index, if it exists.
  • Ensure the right child of the i-th node is at (2*i + 2)-th index, if it exists.
  • You only need to update the array, not create a tree.

Constraints:

  • 1 ≤ T ≤ 10
  • 1 ≤ N ≤ 104
  • -109 ≤ ARR[i] ≤ 109
  • Time Limit: 1 sec
Note:

You don't have to print anything. Just implement the function to convert the array 'ARR' into a min-heap.

Be the first one to answer
Add answer anonymously...
VMware Software Member Technical Staff 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

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