Reported October 2026
ByteDanceheap priority queue

Implement a Heap Priority Queue

Reported by candidates from ByteDance's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live ByteDance OA. Under 2s to a working solution.
Founder's read

ByteDance reported this one in October 2026, and the catch is right in the setup: up to 200000 operations, and you can't use a built-in heap. If you're taking this OA soon, you're writing your own binary min-heap from scratch. A sorted array with insertion or a scan for the minimum on every POP will blow up at that size. The pattern is heap-priority-queue, and the problem is basically a test of whether you can code sift-up and sift-down cleanly under pressure. StealthCoder is the safety net if your mind goes blank mid-assessment, but the structure here is small enough to memorize tonight.

The problem

Implement a min-priority queue of integers without using a built-in priority-queue or heap data structure. Process operations from left to right:
PUSH inserts values[i].
PEEK returns the current minimum without removing it.
POP removes and returns the current minimum.
Collect and return every value produced by PEEK or POP, in operation order. Every observation occurs while the queue is nonempty. Equal values are allowed; values[i] is ignored for observation operations.

Function
runPriorityQueue(operations: String[], values: int[]) → int[]

Examples
Example 1
operations = ["PUSH","PUSH","PEEK","POP","PEEK"]
values = [5,2,0,0,0]
return = [2,2,5]
The minimum after both insertions is 2. POP returns and removes 2, leaving 5.
Example 2
operations = ["PUSH","PUSH","PUSH","POP","POP","POP"]
values = [3,3,1,0,0,0]
return = [1,3,3]
Repeated values remain separate queue entries and are removed in nondecreasing priority order.
Example 3
operations = ["PUSH","PEEK","PUSH","PEEK"]
values = [-4,0,-7,0]
return = [-4,-7]
The second insertion becomes the new minimum.

Constraints
1 <= operations.length == values.length <= 200000.
Each operation is PUSH, PEEK, or POP.
Every PEEK and POP occurs when the queue is nonempty.
Each inserted value is a signed 32-bit integer.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Build an array-backed binary min-heap. PUSH appends the value at the end and sifts up while it's smaller than its parent. PEEK returns index 0. POP saves index 0, moves the last element to the root, shrinks the array, and sifts down by swapping with the smaller child until the heap property holds. Every operation is O(log n), so 200000 operations is trivial. The common pitfalls are off-by-one child indexes (2i+1 and 2i+2), forgetting to handle a heap of size one on POP, and comparing with subtraction, which overflows on signed 32-bit values. Use direct less-than comparisons. Duplicates need no special handling, since equal values just stay as separate entries. Ignore values[i] for PEEK and POP. If you freeze on the sift-down loop during the live OA, StealthCoder can give you the working version while you stay in control.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Implement a Heap Priority Queue cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass ByteDance's OA.

ByteDance reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Implement a Heap Priority Queue FAQ

What's the trick in the ByteDance heap priority queue problem?+

Write a binary min-heap on an array. Sift up on PUSH, sift down on POP, read index 0 on PEEK. The trick is just getting the index math and the swap-with-smaller-child step right. Nothing fancier is needed, and every operation runs in O(log n).

Why can't I just sort or scan for the minimum?+

With up to 200000 operations, scanning for the min on each POP or PEEK is O(n) per call, which gets you around 4 times 10^10 steps in the worst case. Re-sorting after every push is just as bad. The heap keeps each operation at O(log n).

Do duplicates or negative numbers break anything?+

No. Equal values are separate entries, and the heap handles them naturally. Negatives are fine too. Just compare with less-than instead of subtracting, because subtraction can overflow with signed 32-bit integers near the extremes.

How do I prepare for this in 48 hours?+

Write the heap from memory three times in your strongest language. Test it against the three examples, then against a case with all equal values and a case with one element. Once sift-up and sift-down feel automatic, you're done.

Is the heap pattern still asked in 2026 OAs?+

Yes. ByteDance reported this one in October 2026, and heap-based questions keep showing up in OAs. Building the structure yourself, instead of calling a library, is a common twist, so know the internals.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with ByteDance.

OA at ByteDance?
Invisible during screen share
Get it