Challenge: Is Tree a Heap?

Let’s check if a tree is also min heap or not.


Given a binary tree, find if it represents a min heap.

Note: A min heap is a complete binary tree where the data stored in the parent node is smaller than the data in both of the child nodes.


A binary tree.


Return true if the tree is a heap, otherwise return false.

Sample input

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.