[
array
heap
]
BinarySearch 0511 Verify Max Heap
Problem statement
https://binarysearch.com/problems/Verify-Max-Heap/
Solution
Just check what is asked.
Complexity
It is O(n)
for time and space.
Code
class Solution:
def solve(self, A):
n = len(A)
for i in range(n//2):
if 2*i + 1 < n and A[i] < A[2*i + 1]: return False
if 2*i + 2 < n and A[i] < A[2*i + 2]: return False
return True