content: class Solution {
      private void swap(int[] arr, int index1, int index2) {
          int temp = arr[index1];
          arr[index1] = arr[index2];
          arr[index2] = temp;
      }
      
      // Function to heapify a subtree (in top-down order) rooted at index i.
      private void heapify(int[] arr, int n, int i) {
          // Initialize largest as root 'i'.
          int largest = i; 
          int left = 2 * i + 1;
          int right = 2 * i + 2; 
  
          // If left child is larger than root.
          if (left < n && arr[left] > arr[largest]) {
              largest = left;
          }
  
          // If right child is larger than largest so far.
          if (right < n && arr[right] > arr[largest]) {
              largest = right;
          }
  
          // If largest is not root swap root with largest element
          // Recursively heapify the affected sub-tree (i.e. move down).
          if (largest != i) {
              swap(arr, i, largest); 
              heapify(arr, n, largest);
          }
      }
  
      private void heapSort(int[] arr) {
          int n = arr.length;
          // Build heap; heapify (top-down) all elements except leaf nodes.
          for (int i = n / 2 - 1; i >= 0; i--) {
              heapify(arr, n, i);
          }
  
          // Traverse elements one by one, to move current root to end, and
          for (int i = n - 1; i >= 0; i--) {
              swap(arr, 0, i);
              // call max heapify on the reduced heap.
              heapify(arr, i, 0);
          }
      }
  
      public int[] sortArray(int[] nums) {
          heapSort(nums);
          return nums;
      }
  }