Solution: Implement Queue Using Stacks

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

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.