input: Write a Python function to sort an array using the heap sort algorithm.
  assert heap_sort([12, 2, 4, 5, 2, 3]) == [2, 2, 3, 4, 5, 12]
  assert heap_sort([32, 14, 5, 6, 7, 19]) == [5, 6, 7, 14, 19, 32]
  assert heap_sort([21, 15, 29, 78, 65]) == [15, 21, 29, 65, 78]
output: def heap_sort(arr):
      def heapify(arr, n, i):
          largest = i
          l = 2 * i + 1
          r = 2 * i + 2
          if l < n and arr[l] > arr[largest]:
              largest = l
          if r < n and arr[r] > arr[largest]:
              largest = r
          if largest != i:
              arr[i], arr[largest] = arr[largest], arr[i]
              heapify(arr, n, largest)
  
      n = len(arr)
      for i in range(n // 2 - 1, -1, -1):
          heapify(arr, n, i)
  
      for i in range(n - 1, 0, -1):
          arr[i], arr[0] = arr[0], arr[i]
          heapify(arr, i, 0)
  
      return arr