FastPrepImplement a Queue Using Stacks
Problems/Implement a Queue Using Stacks

Implement a Queue Using Stacks

AMD logoAMD● MediumFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The source says implement a Queue using a Stack without specifying stack count. Allowing two stacks, finite operations, bounds and empty behavior are authored completion; approximate source match90%.

Implement first-in-first-out queue behavior using stacks: push, pop, top and size are the permitted storage operations; do not use a queue/deque operation that removes from the opposite end. Two stacks are allowed. Return one result per trace entry:0 for enqueue, the removed front for dequeue, the current front for peek, and the item count for size. Empty dequeue/peek return-2147483648, outside the payload domain. Start empty.

Function

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

Examples

Example 1

operations = [[0,4],[0,7],[2,0],[1,0],[3,0]]return = [0,0,4,4,1]

Enqueuing4 before7 leaves4 at the front; removing it leaves one item.

Example 2

operations = [[0,1],[0,2],[1,0],[0,3],[1,0],[1,0],[1,0]]return = [0,0,1,0,2,3,-2147483648]

The dequeue order is1,2,3; one additional dequeue is empty.

Constraints

  • 0 <= operations.length <= 500.
  • Every operation has exactly two entries.
  • -1000000 <= operations[i][j] <= 1000000.
  • Every operation is [kind,value], with kind in 0..3. Kind0 adds value; kind1 removes and returns the front item; kind2 returns it without removal; kind3 returns the current size. The second entry is ignored for kinds1..3.

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