Heap in interviews

Use below simulation
Pasted image 20250626093556.png


class FakeMinHeap {

  constructor() {
    this.data = [];
  }

  push(val) {
    this.data.push(val);
    this.data.sort((a, b) => a - b); // Always keep the smallest at index 0
  }

  pop() {
    return this.data.shift(); // Removes the smallest
  }

  peek() {
    return this.data[0];
  }

  size() {
    return this.data.length;
  }
}