Challenge: Is Tree a Heap?

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

Problem

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.

Input

A binary tree.

Output

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

Sample input

Get hands-on with 1400+ tech skills courses.