Welcome to the daily solving of our PROBLEM OF THE DAY with Siddharth Hazra. We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Heap but also build up problem-solving skills.
In this problem, we are given an array arr of size n, the task is to check if the given array can be a level order representation of a Max Heap.
Example :
Input:
n = 6
arr[] = {90, 15, 10, 7, 12, 2}
Output:
1
Explanation:
The given array represents below tree
90
/ \
15 10
/ \ /
7 12 2
The tree follows max-heap property as every node is greater than all of its descendants.
Give the problem a try before going through the video. All the best!!!
Problem Link: https://www.geeksforgeeks.org/problems/does-array-represent-heap4345/1