DSA interview question
A monitoring tool receives a priority queue's internal array from another service and must validate it before trusting it: does the array satisfy the min-heap property? In array form, node i's children are at 2i + 1 and 2i + 2, so the check is simply that every parent is ≤ each child that exists. Only the first half of the array has children, so the loop can stop at index n/2 − 1.
Example: [10, 15, 14, 25, 30] → true; [2, 1] → false.
bool isMinHeap(const vector<int>& a);
| Input | Output | Explanation |
|---|---|---|
[10, 15, 14, 25, 30] | true | |
[30, 56, 22, 49, 30, 51, 2, 67] | false | 30 > 22 at the root |
[1, 2, 3, 4, 5, 6] | true | A sorted array is always a min-heap |
[2, 1] | false | |
[3, 3, 3] | true | Equal values are allowed |
[5] | true |
(Confirm: the array is a complete binary tree in level order; equal parent and child values are allowed.)
On Practick another engineer interviews you live for 60 minutes on a question from this bank. They have the full interviewer guide beside the call: the expected answer to every follow-up, hints to give if you stall, and a scoring rubric. You get the model solution once the session settles. It is free: interview someone for an hour and you have earned your own.
Book a free mock interviewAll 474 dsa interview questions
DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in