FastPrepGrowing Circular Queue
Problems/Growing Circular Queue

Growing Circular Queue

AMD logoAMD● MediumFULLTIMENEW GRADONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The source describes producer-consumer operations, a circular queue initially sized 10, and bursts reaching 500 without data loss. The ordered operation interface, doubling policy, query results and empty result are defined for practice.

Implement a FIFO queue that starts empty with capacity 10 and preserves every value during growth. Process the given operations in order. Each operation is a pair [type, value].

  • [0, value]: produce a value at the back and return the new size. If the queue is full, double its capacity before insertion.
  • [1, 0]: consume and return the front value, or return -1 when empty.
  • [2, 0]: return the current size.
  • [3, 0]: return the current capacity.

Return one integer result for each operation. Capacity never shrinks. Use a resizable circular buffer so that insertion and removal take amortized constant time.

Function

processQueue(operations: int[][]) → int[]

Examples

Example 1

operations = [[0,7],[0,8],[1,0],[2,0],[3,0],[1,0],[1,0]]return = [1,2,7,1,10,8,-1]

The two insertions return sizes 1 and 2. The first removal returns 7, leaving size 1 and capacity 10. The next removal returns 8; removing from the empty queue returns -1.

Example 2

operations = [[3,0],[0,0],[1,0],[3,0]]return = [10,1,0,10]

Capacity starts at 10. Inserting the value 0 returns size 1, and consuming it returns 0. Removing a value does not shrink capacity.

Constraints

  • 0 <= operations.length <= 10000.
  • Every operation has exactly 2 integers.
  • Every integer in operations is between 0 and 1000000000, inclusive.
  • The first integer is one of 0, 1, 2, or 3. For types other than 0, the second integer is 0.

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[] processQueue(int[][] operations) {
    // Write your code here.
}
Checking account…