Binary Min-Heap Operations
Updated
Problem statement
Implement a min-heap and process operations on an initially empty collection:
[0,value]: insert one copy ofvalue.[1,0]: return the smallest stored value without removing it, or-1if empty.[2,0]: remove and return one copy of the smallest stored value, or-1if empty.
Return the results of type-1 and type-2 operations in operation order. Duplicate values are independent copies. Implement the heap structure yourself rather than using a library priority queue.
Function
minHeapOperations(operations: int[][]) → int[]Examples
Example 1
operations = [[0,5],[0,2],[0,7],[1,0],[2,0],[1,0],[2,0],[2,0],[2,0]]return = [2,2,5,5,7,-1]The three inserted values are 5, 2, and 7. Peeking returns 2 and leaves it in the heap. The removals then return 2, 5, and 7, with a peek of 5 between the first two removals. The last removal returns -1 because the heap is empty.
Example 2
operations = [[0,3],[0,3],[2,0],[1,0],[2,0],[1,0]]return = [3,3,3,-1]Removing one copy of 3 leaves the other copy available. After both copies are removed, the final peek returns -1.
Constraints
0 <= operations.length <= 100000.- Every operation contains exactly two integers.
- The operation code is 0, 1, or 2.
0 <= value <= 10^9.- Peek and removal operations have a second value of zero.
More Citadel Phone Screen questions
- Portfolio Tickers with Constant-Time Random PickPHONE SCREEN · Seen Nov 2026
- Square Root FunctionPHONE SCREEN · Seen Oct 2026
- Reachable Transfer PositionsPHONE SCREEN · Seen Oct 2026
- Spreadsheet Formula DependenciesPHONE SCREEN · Seen Oct 2026
- Merge Price-Delta FeedsPHONE SCREEN · Seen Sep 2026
- Reconcile Unmatched Trades with Timestamp TolerancePHONE SCREEN · Seen Sep 2026
- Top Ten Trades by Notional ValuePHONE SCREEN · Seen Sep 2026
- Exchange BBO and Market-Wide NBBOPHONE SCREEN · Seen Sep 2026
- Maximize Workday EarningsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Minimum Changes for Palindromic BlocksOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Running Medians and PercentilesStackAdapt · PHONE SCREENStackAdapt interview questions
- Top K Largest Values from a StreamThe D.E. Shaw Group · ONSITE INTERVIEWThe D.E. Shaw Group interview questions
- Fixed-K Kth Largest StreamAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
- Fixed-K Kth Largest StreamGoogle · ONSITE INTERVIEWGoogle interview questions
- Top K With a Deterministically Noisy Comparator (MLE)Mercor · ONSITE INTERVIEWMercor interview questions
- Customer Bootstrap APIDoorDash · PHONE SCREEN · ONSITE INTERVIEWDoorDash interview questions
- Design Hit CounterCharta Health · PHONE SCREENCharta Health interview questions
- Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
- Task Scheduler with Prerequisites and Execution PathsBrex · PHONE SCREEN
- Streaming Median of Trade PricesXantium · PHONE SCREEN