Continue learning
Practice related DSA questions in the same topic.
Return 1 if each parent in the complete level-order tree is at least as large as each child, otherwise 0.
Return 1 if each parent in the complete level-order tree is at least as large as each child, otherwise 0.
def solve(values, target): child = 1 while (child < len(values)): parent = ((child - 1) // 2) if (values[parent] < values[child]): return 0 child = (child + 1) return 1Compare parent 0 with child 1.
Compare parent 0 with child 1.
A tournament ranking tree places each winner above both children.
Every non-root entry has exactly one parent; verify one relation per child.
O(n) time · O(1) auxiliary space
Worked example · {"values":[9,5,8,2,3],"target":0} ⇒ 1
Edge case 1 · {"values":[1,3],"target":0} ⇒ 0
Edge case 2 · {"values":[],"target":0} ⇒ 1
A heap is only locally ordered. Siblings can be in either order.
How can a heap expose the maximum in constant time?