...

/

Solution: Implement Queue Using Stacks

Solution: Implement Queue Using Stacks

Let’s solve the Implement Queue Using Stacks problem.

Statement

Design a queue data structure using only two stacks and implement the following functions:

  • enqueue(int x): Inserts a value to the back of the queue.
  • dequeue(): Removes and returns the value from the front of the queue.

Constraints:

  • 105-10^5 \leq x 105\leq 10^5
Access this course and 1400+ top-rated courses and projects.