Implement Queue using Stacks (Round 2, LC 232:)

Problem Overview

  • Build a FIFO queue using only two stacks; implement MyQueue with push(x), pop(), peek(), and empty().
  • Constraints: x in 1–9, up to 100 operations; pop and peek are always valid; only standard stack ops allowed.
  • Domain: data structures design; queue via stacks used in software systems.
  • From Microsoft interviews: a coding interview problem (LC 232) and a common interview question.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: