Leaderboard
Showing:
Handle Score
@Ibrahim Nash 6560
@blackshadows 6400
@mb1973 5777
@Quandray 5271
@akhayrutdinov 5111
@saiujwal13083 5074
@kirtidee18 4356
@sanjay05 3762
@mantu_singh 3638
@gfgaccount 3601
@marius_valentin_dragoi 3525
Complete Leaderboard
Is Binary Tree Heap
Easy Accuracy: 50.0% Submissions: 23296 Points: 2

Given a binary tree you need to check if it follows max heap property or not.

Input:
The task is to complete the method which takes one argument, root of Binary Tree. The struct Node has a data part which stores the data, pointer to left child and pointer to right child.There are multiple test cases. For each test case, this method will be called individually.

Output:
The function should return true if property holds else false.

 

Example 1:

Input:
      5
    /  \
   2    3
Output: 1

Example 2:

Input:
       10
     /   \
    20   30 
  /   \
 40   60
Output: 0

Constraints:
1 ≤ Number of nodes ≤ 100
1 ≤ Data of a node ≤ 1000

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Is Binary Tree Heap

Output Window