FastPrepBounded FIFO Queue
Problems/Bounded FIFO Queue

Bounded FIFO Queue

AMD logoAMD● EasyFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The fifth round asked the candidate to model a FIFO. The report gives no capacity, API or full/empty rules. This exercise uses a bounded, initially empty queue and sequential enqueue/dequeue operations with explicit return values. The separate earlier pipeline/IPC exercise is a different task. Approximate source match: 80%.

Model a FIFO queue that starts empty and holds at most capacity integers. Process operations in order.

  • [0, value] tries to enqueue value at the back. Return 1 if it is accepted. If the queue is full, leave it unchanged and return 0.
  • [1, 0] dequeues and returns the front value. If the queue is empty, leave it unchanged and return -1.

Return one integer per operation. The queue never grows. No concurrency or blocking behavior is required.

Function

fifoResults(capacity: int, operations: int[][]) → int[]

Examples

Example 1

capacity = 2operations = [[0,4],[0,9],[0,7],[1,0],[1,0],[1,0]]return = [1,1,0,4,9,-1]

4 and 9 fill the queue. The attempted enqueue of 7 is rejected. Dequeues return 4, then 9, then -1 because the queue is empty.

Example 2

capacity = 1operations = [[0,0],[1,0],[0,8],[1,0]]return = [1,0,1,8]

The value 0 is valid data. Removing it frees the only slot, so 8 can then be enqueued and removed.

Example 3

capacity = 3operations = []return = []

An empty operation batch produces an empty result array.

Constraints

  • 1 <= capacity <= 10000.
  • 0 <= operations.length <= 10000.
  • Each operation has exactly two integers. Its type is 0 or 1. An enqueue value is from 0 through 1000000; a dequeue uses 0 as its second entry.

More AMD problems

  • Insert After a Linked-List NodeONSITE INTERVIEW · Seen Oct 2026
  • LRU CacheONSITE INTERVIEW · Seen Oct 2026
  • Lowest Common Ancestor of a Binary TreePHONE SCREEN · Seen Oct 2026
All AMD interview questionsSee AMD hiring insights
Saved
public int[] fifoResults(int capacity, int[][] operations) {
    return new int[0];
}
Checking account…