Heap Sort Problem Statement

Your task is to sort an array of integers in non-decreasing order using the Heap Sort algorithm.

Input:

The first line contains an integer 'T' denoting the number of test cases.
Each test case consists of two lines:
- The first line contains a single integer 'N', the number of elements in the array.
- The second line contains 'N' space-separated integers, the elements of the array.

Output:

For each test case, output 'N' space-separated integers sorted in non-decreasing order.
Each test case's output should be on a separate line.

Example:

Input:

2
4
4 10 3 5
3
9 7 6

Output:

3 4 5 10
6 7 9

Constraints:

  • 1 <= T <= 10
  • 1 <= N <= 105
  • -109 <= ARR[i] <= 109

Note:

Implement the function; you do not need to handle any printing as it has been managed externally.
AnswerBot
4mo

Heap Sort is used to sort an array of integers in non-decreasing order by creating a max heap and repeatedly extracting the maximum element.

  • Create a max heap from the input array.

  • Swap the root (maximu...read more

Help your peers!
Select
Add answer anonymously...
RadiSys Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits