PPractick

DSA interview question

Check If an Array Represents a Min Heap

Medium · Data structures · Topics: heap, array

The problem

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.

Function signature

bool isMinHeap(const vector<int>& a);

Test cases

InputOutputExplanation
[10, 15, 14, 25, 30]true
[30, 56, 22, 49, 30, 51, 2, 67]false30 > 22 at the root
[1, 2, 3, 4, 5, 6]trueA sorted array is always a min-heap
[2, 1]false
[3, 3, 3]trueEqual values are allowed
[5]true

(Confirm: the array is a complete binary tree in level order; equal parent and child values are allowed.)

How interviewers phrase it

Clarifying questions to ask

  1. Min-heap or max-heap?
  2. Is equality allowed between parent and child? (Yes.)
  3. Is the array guaranteed to be complete? (Yes: arrays represent complete trees by construction.)

Follow-ups to expect

  1. "Which indices have children?"
  2. "Why is checking parent against child enough?"
  3. "Recursive version?"
  4. "Standard library?"
  5. "Complexity?"

Practise questions like this with a real engineer

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 interview

Related questions

All 474 dsa interview questions

DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in