As reported: Microsoft Senior Software Engineer (L63, India, Dec 2025), round 5 with an Engineering Group Director: implement Java's
PriorityQueue(a min-heap) without using libraries. Also: Microsoft SDE-1 L60, Xbox team (Hyderabad, Aug 2025), round 1 (DSA, 60 minutes): implement a min heap from scratch.
Implement a MinHeap of integers without any library heap or priority queue (no java.util.PriorityQueue, heapq, std::priority_queue, container/heap):
MinHeap()creates an empty heap.push(val)addsval.pop()removes and returns the smallest value.peek()returns the smallest value without removing it.size()returns the number of values stored.
Example
ops = ["MinHeap","push","push","push","peek","pop","pop","size"]
args = [[],[5],[3],[8],[],[],[],[]]
-> [null,null,null,null,3,3,5,1]
Constraints: at most 10^5 calls; values fit in a 32-bit signed integer; pop and peek are only called on a non-empty heap; duplicates are allowed.
Code runner format: LeetCode's design format: the operation names on the first line, their arguments on the second. Implement the class (in Go: Constructor() and methods Push, Pop, Peek, Size); the harness prints the list of results.