FastPrepHeap Sort
Problems/Heap Sort

Heap Sort

Rippling logoRippling● MediumFULLTIMEOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report identifies a max-heap-sort question without preserving its original array or choices. This practice version implements that named algorithm; the ascending output, variable interface, empty case and bounds are authored. Source match is about 65%.

Given an integer array nums, return all its elements sorted from smallest to largest. Keep duplicate values. An empty array returns an empty array.

Practice implementing heap sort: build a max heap, repeatedly move its maximum into the last position of the unsorted prefix, and repair the smaller heap. The returned values are judged; no particular intermediate heap layout is required.

Function

heapSort(nums: int[]) → int[]

Examples

Example 1

nums = [6,15,2,4,3,8,19]return = [2,3,4,6,8,15,19]

Each extraction places the current largest value at the end of the remaining prefix.

Example 2

nums = [3,-1,3,0]return = [-1,0,3,3]

Negative values and duplicate threes are retained.

Example 3

nums = []return = []

No construction or extraction is needed.

Constraints

  • 0 <= nums.length <= 100000.
  • Every element is a signed 32-bit integer.

More Rippling problems

  • Stateful Log Transform and SearchPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Dependency-Aware Task SchedulerPHONE SCREEN · Seen Nov 2026
  • Filter, Sort, and Deduplicate Scheduled TasksPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
All Rippling interview questionsSee Rippling hiring insights
Saved
public int[] heapSort(int[] nums) {
    // Write your code here.
}
Checking account…