Loading...
Loading...
Loading...
A scheduler stores task priorities in a list. In a min-heap, the item at index i (counting from 0) is never smaller than its parent at index (i - 1) // 2. Print YES if the list follows this rule everywhere and NO if not. A smaller number means a more urgent task.
Example 1
Input
7 1 3 2 7 4 5 6
Output
YES
Every item is at least as large as its parent.
Example 2
Input
3 3 2 1
Output
NO
Try the problem first. Open one hint at a time.
Index i has its parent at (i - 1) // 2, so compare each item with that one.
Start from index 1. Index 0 has no parent.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor