Skip to content
CampusEduX

Queue Using Two Stacks

Mediumjavapythonccppjavascript

Implement a queue using only two stacks, so that operations still behave in First In, First Out order.

Input Format

The first line contains an integer Q. Each of the next Q lines is one of: enqueue X, dequeue, front, empty.

Output Format

For each dequeue or front, print the element (or -1 if empty). For each empty, print 1 if empty, otherwise 0. One value per line.

Related Problems

  • Next Greater Element
    Medium · java, python, c, cpp, javascript
    Solve Problem
  • Next Smaller Element
    Medium · java, python, c, cpp, javascript
    Solve Problem
  • Min Stack
    Medium · java, python, c, cpp, javascript
    Solve Problem

Input (stdin)

Output

Run your code to see output here...