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
1mo
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!
Add answer anonymously...
Top TCS Assistant System Engineer interview questions & answers
Popular interview questions of Assistant System Engineer
Top HR questions asked in TCS Assistant System Engineer
Stay ahead in your career. Get AmbitionBox app
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
Get AmbitionBox app