
Asked in Jaguar Land Rover
Build Max Heap Problem Statement
Given an integer array with N elements, the task is to transform this array into a max binary heap structure.
Explanation:
A max-heap is a complete binary tree where each internal node has a value greater than or equal to its children. The given integer array needs to be rearranged to satisfy the max-heap property.
Input:
The first line of input contains an integer T, representing the number of test cases. Each test case consists of two lines: the first line contains the integer N (size of the array), and the second line contains N space-separated integers that represent the elements of the array.
Output:
For each test case, output '1' if the transformed array represents a max-heap, otherwise output '0'. Each test case result should be printed on a new line.
Example:
Input:
1
5
3 1 5 2 4
Output:
1
Constraints:
1 <= T <= 10
1 <= N <= 10^4
-10^9 <= data <= 10^9
Note:
You do not need to print the heap; simply ensure that the returned array satisfies the max-heap condition using 0-based indexing. In a 0-based index array:
- The left child of the ith node is at (2 * i + 1)th index.
- The right child of the ith node is at (2 * i + 2)th index.
- The parent of the node at the ith index is at (i - 1) / 2 index.

AnswerBot
5mo
The task is to transform an integer array into a max binary heap structure.
Create a max heap from the given array by rearranging elements.
Check if each internal node has a value greater than or equal ...read more
Help your peers!
Add answer anonymously...
Interview Questions Asked to Technical Trainee at Other Companies
Top Skill-Based Questions for Jaguar Land Rover Technical Trainee
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

