Queue Using Two Stacks

Implement a queue using two stacks. Your implementation should support the following operations:

  • enqueue(value) - Add element to the queue
  • dequeue() - Remove element from the queue
  • peek() - Get the front element
  • isEmpty() - Check if queue is empty

All operations should run in amortized O(1) time complexity.

Examples
Input: [["Queue","enqueue","enqueue","dequeue","peek"],[[],[1],[2],[],[]]]
Output: [null,null,null,1,2]
Hints

Queue Using Two Stacks

Implement a queue using two stacks. Your implementation should support the following operations: