Reported October 2026
ByteDancequeue

Implement a FIFO 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 it looks too easy until the input size bites. You implement a FIFO queue from scratch, no built-in queue or deque, and replay up to 100000 operations. The pattern is plain queue simulation. The trap is the naive approach: shifting an array on every pop turns the run into quadratic time. If you've got the OA open in a day or two, know the head-pointer trick cold. StealthCoder sits invisibly as a safety net if your mind goes blank on the live assessment.

The problem

Implement the behavior of a first-in, first-out queue without using a built-in queue or deque type.
Process the paired arrays operations and values from left to right:
push: append values[i] to the back of the queue.
pop: remove the value at the front and append that value to the result.
peek: append the value at the front to the result without removing it.
Return all values produced by pop and peek, in operation order. A push operation produces no result.

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

Examples
Example 1
operations = ["push","push","peek","pop","peek"]
values = [4,7,0,0,0]
return = [4,4,7]
The first peek reads 4. The following pop removes and returns 4, so the final peek reads 7.
Example 2
operations = ["push","push","pop","push","peek","pop","pop"]
values = [10,20,0,30,0,0,0]
return = [10,20,20,30]
After removing 10, pushing 30 leaves the queue as [20,30]. The remaining operations read and remove those values in FIFO order.
Example 3
operations = ["push","push","peek","pop","peek","pop"]
values = [-2,-2,0,0,0,0]
return = [-2,-2,-2,-2]
Equal and negative values retain their insertion order. A peek does not remove the front value.

Constraints
1 <= operations.length == values.length <= 100000.
Each operation is push, pop, or peek.
For push, -10^9 <= values[i] <= 10^9; for other operations, values[i] is ignored.
Every pop or peek occurs while the queue is nonempty.
Do not use a built-in queue or deque type.

Reported by candidates. Source: FastPrep

Pattern and pitfall

With 100000 operations, removing from the front of an array by shifting costs O(n) each time, so a pop-heavy input gives you roughly 5 billion element moves in the worst case. The fix is a plain array plus a head index. Push appends to the back. Peek reads the array at head. Pop reads at head, then increments head. Nothing shifts, so every operation is O(1) and the whole run is O(n). Memory is fine since you never need to reclaim the front. Pitfalls: forgetting that peek must not advance the head, and appending push results to the output by mistake. Push produces nothing. The constraints guarantee the queue is nonempty on pop and peek, so skip empty checks. Ignore values[i] for non-push operations. If you freeze on the live OA, StealthCoder can hand you this head-pointer solution in seconds.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Implement a FIFO 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 for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as implement queue using stacks. If you have time before the OA, drill that.

⏵ The honest play

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

ByteDance reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Implement a FIFO Queue FAQ

What's the trick in the ByteDance FIFO queue problem?+

Don't shift the array on pop. Keep a dynamic array and a head index. Push appends, pop reads the head and moves the index forward, peek reads the head without moving it. Every operation is O(1), which matters at 100000 operations.

How hard is this problem really?+

It's easy on logic and only slightly tricky on efficiency. If you know the head-pointer idea, it's about ten lines. The only way to fail is using an O(n) front removal and timing out on large inputs.

Can I use a linked list instead of an array with a head index?+

Yes. A singly linked list with head and tail pointers gives O(1) push and pop too. The array plus head index is shorter and less error-prone, so it's the safer pick under time pressure. Either satisfies the no-built-in-queue rule.

What should the output contain for push operations?+

Nothing. Only pop and peek add values to the result, in operation order. A common bug is appending a placeholder for push, which breaks the expected output length. Check your result against Example 1: [4,4,7].

How do I prepare for this in 48 hours?+

Write the head-index queue from memory once, then trace the three examples by hand, especially the one with duplicate negative values. Also practice a two-stack queue variant in case a follow-up asks. That covers most queue simulation questions.

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