Skip to main content
Beginner~5 min · +40 XP

Stack vs Queue Output

Practices: Stacks

Problem

You push 1, 2, 3 into a stack (in that order), then pop twice. Separately, you enqueue A, B, C into a queue, then dequeue twice.

What is the concatenation of the two popped values followed by the two dequeued values? (Format: like 32AB)

Examples

  • in: push 1,2 then pop once; enqueue A,B then dequeue once

    out: 1A

    Stack pops the most recent (1 was the only one); queue dequeues the first arrival (A).

Constraints & conventions

  • Stack = LIFO (last in, first out). Queue = FIFO (first in, first out).

Your answer

Solve the challenge to unlock the full approach and complexity analysis.