Baseline Heaps · Learning O(log n) insert/remove, O(1) peek · O(n)
An emergency room keeps a triage board where the most critical patient is always at the top. New arrivals slot in without breaking that rule, and discharging the top patient promotes exactly one successor. The board supports three moves: admit a patient, discharge the most critical one, and peek at who is next. Build the board so every operation stays logarithmic.
Input: A list of operations: ["insert", value], ["removeMin"], or ["minElement"].
Output: Return the list of values produced by every minElement operation, in order; a peek on an empty heap yields -1.
1 <= number of operations <= 10^5-10^9 <= values <= 10^9insert, removeMin: O(log n); minElement: O(1)Input: {"operations":[["insert",5],["insert",3],["insert",8],["minElement"],["removeMin"],["minElement"]]}
Output: [3,5]
3 bubbles to the top; after discharging it, 5 becomes the new minimum.
Input: {"operations":[["minElement"],["insert",-2],["minElement"]]}
Output: [-1,-2]
Peeking an empty board returns -1 before any patient arrives.