[Approach] Using Recursion - O(n) Time and O(log n) Space
To build a Max Heap from an array, treat the array as a complete binary tree and heapify nodes from the last non-leaf node up to the root in reverse level order. Leaf nodes already satisfy the heap property, so we start from the last non-leaf node, and for each subtree, we compare the parent with its children. Whenever a child node is greater than the parent, we swap them and continue heapifying that subtree to ensure the Max Heap property is maintained throughout.
Note :
Root is at index 0.
Left child of node i -> 2*i + 1.
Right child of node i -> 2*i + 2.
Parent of node i -> (i-1)/2.
Last non-leaf node -> parent of last node -> (n/2) - 1.