Problem, as an interviewer would state it:
"Implement a priority queue using a binary MIN-HEAP, backed by a plain array — support insert(value) and extractMin(), both in O(log n)."
Examples:
const heap = new MinHeap();
[5, 3, 8, 1].forEach(n => heap.insert(n));
heap.extractMin(); // 1
heap.extractMin(); // 3
Clarifying questions expected:
- Is a plain array-backed heap (using index arithmetic for parent/child relationships) the expected approach, or a real linked tree structure?
- Should this be a min-heap or a max-heap — and does the comparison logic need to be configurable?
- What should extractMin() return on an empty heap?
Code / implementation expected: Yes — real, direct proof: insert a real, randomly-ordered sequence, then confirm repeated extractMin() calls produce the exact correct, genuinely sorted order.