Practice arena
C++17·2 s·128 MB
HeapsFoundation
Is it a min heap?
Determine whether every parent in an array representation is less than or equal to its children, making the array a valid min heap.
Input
- — The first line contains T.
- — Each case contains n followed by n integers in level order.
Output
Print YES for a valid min heap; otherwise print NO.
Technique
parent-child index checks
Target
O(n)
Constraints & sample
- 1 ≤ n ≤ 200,000
- Equal parent and child values are allowed
Sample input
3 6 1 3 2 7 6 4 4 2 1 3 4 5 1 1 2 3 4
Expected output
YES NO YES
Before you submit
- Test the smallest valid input and one awkward edge case.
- Keep the solution within O(n).
- Match spacing and line breaks exactly before checking 8 hidden cases.
Draft saved locally · 455 / 30,000
Ln 1, Col 1Spaces: 4UTF-8LFC++17
Visible testcases
Editable and stored only in this browser. Hidden judge cases never change.
Checking your session…
Run checks Sample · Submit checks 8 hidden cases
Run the sample first, then send your solution through 8 hidden cases.
Code runs in an isolated Judge0 environment. Drafts and custom visible cases stay on this device; submission metadata and progress sync to MongoDB.