codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

ProblemsImplement Queue using Stacks

Implement Queue using Stacks

Easy
StacksDesign

Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (push, peek, pop, and empty).

 

Example 1:

Input:
["MyQueue", "push", "push", "peek", "pop", "empty"]
[[], [1], [2], [], [], []]
Output: [null, null, null, 1, 1, false]

 

Constraints:

  • 1 <= x <= 9
  • At most 100 calls will be made to push, pop, peek, and empty.

Related Problems

View all
Valid Parentheses
Easy•Stacks-queues
Min Stack
Medium•Stacks-queues
Evaluate Reverse Polish Notation
Medium•Stacks-queues
Generate Parentheses
Medium•Stacks-queues
Daily Temperatures
Medium•Stacks-queues
Car Fleet
Medium•Stacks-queues
Input:
["MyQueue", "push", "push", "peek", "pop", "empty"] [[], [1], [2], [], [], []]