Verify Max Heap
Given a list of integers nums
, return whether it represents a max heap. That is, for every i
we have that:
nums[i] ≥ nums[2*i + 1]
if2*i + 1
is within boundsnums[i] ≥ nums[2*i + 2]
if2*i + 2
is within bounds
Constraints
0 ≤ n ≤ 100,000
wheren
is the length ofnums
https://binarysearch.com/problems/Verify-Max-Heap
Examples
Example 1
Input
- nums =
[4, 2, 3, 0, 1]
Output
- answer =
True
Leave a comment