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).

Implement the MyQueue class:


	void push(int x) Pushes element x to the back of the queue.
	int pop() Removes the element from the front of the queue and returns it.
	int peek() Returns the element at the front of the queue.
	boolean empty() Returns true if the queue is empty, false otherwise.


Notes:


	You must use only standard operations of a stack, which means only push to top, peek/pop from top, size, and is empty operations are valid.
	Depending on your language, the stack may not be supported natively. You may simulate a stack using a list or deque (double-ended queue) as long as you use only a stack's standard operations.


&nbsp;
Example 1:

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

Explanation
MyQueue myQueue = new MyQueue();
myQueue.push(1); // queue is: [1]
myQueue.push(2); // queue is: [1, 2] (leftmost is front of the queue)
myQueue.peek(); // return 1
myQueue.pop(); // return 1, queue is [2]
myQueue.empty(); // return false


&nbsp;
Constraints:


	1 &lt;= x &lt;= 9
	At most 100&nbsp;calls will be made to push, pop, peek, and empty.
	All the calls to pop and peek are valid.


&nbsp;
Follow-up: Can you implement the queue such that each operation is amortized O(1) time complexity? In other words, performing n operations will take overall O(n) time even if one of those operations may take longer.

class MyStack:
    def __init__(self):
        self.stack = []

    def push(self, x):
        self.stack.append(x)

    def top(self):
        return self.stack[-1]

    def pop(self):
        return self.stack.pop()

    def size(self):
        return len(self.stack)

    def isEmpty(self):
        return len(self.stack) == 0

class MyQueue:

    def __init__(self):
        self.stack1 = MyStack()
        self.stack2 = MyStack()

    def push(self, x: int) -> None:
        self.stack1.push(x)

    def pop(self) -> int:
        while not self.stack1.isEmpty():
            self.stack2.push(self.stack1.pop())
        out = self.stack2.pop()
        while not self.stack2.isEmpty():
            self.stack1.push(self.stack2.pop())
        return out

    def peek(self) -> int:
        while not self.stack1.isEmpty():
            self.stack2.push(self.stack1.pop())
        out = self.stack2.top()
        while not self.stack2.isEmpty():
            self.stack1.push(self.stack2.pop())
        return out

    def empty(self) -> bool:
        return self.stack1.isEmpty()

# Your MyQueue object will be instantiated and called as such:
# obj = MyQueue()
# obj.push(x)
# param_2 = obj.pop()
# param_3 = obj.peek()
# param_4 = obj.empty()
class MyQueue {

    private final Deque<Integer> stack = new ArrayDeque<>();
    private final Deque<Integer> temp = new ArrayDeque<>();

    /**
     * Initialize your data structure here.
     */
    public MyQueue() {}

    /**
     * Pushes element x to the back of the queue.
     */
    public void push(int x) {
        stack.push(x);
    }

    /**
     * @return the element at the front of the queue and remove it.
     */
    public int pop() {
        while (stack.size() > 1)
            temp.push(stack.pop());

        var val = stack.pop();
        while (!temp.isEmpty())
            stack.push(temp.pop());

        return val;
    }

    /**
     * @return the element at the front of the queue.
     */
    public int peek() {
        while (stack.size() > 1)
            temp.push(stack.pop());

        var val = stack.peek();
        while (!temp.isEmpty())
            stack.push(temp.pop());

        return val;
    }

    /**
     * @return true if the queue is empty, false otherwise.
     */
    public boolean empty() {
        return stack.isEmpty();
    }
}
class MyQueue {
public:
    stack<int>s1;
    stack<int>s2;

    MyQueue() {
        
    }
    
    void push(int x) {
        s1.push(x);
    }
    
    int pop() {
        if(s1.empty() && s2.empty()) return -1;
        while(s2.empty()){
        while(!s1.empty()){
            s2.push(s1.top());
            s1.pop();
        }
        }
        int x = s2.top();
        s2.pop();
        return x;
    }
    
    int peek() {
        if(!s2.empty()){
            return s2.top();
        }
        else{
            while(!s1.empty()){
                int val = s1.top();
                s2.push(val);
                s1.pop();
            }
            return s2.top();
        }
    }
    
    bool empty() {
        if(s1.empty() && s2.empty()){
            return true;
        }
        return false;
    }
};

/**
 * Your MyQueue object will be instantiated and called as such:
 * MyQueue* obj = new MyQueue();
 * obj->push(x);
 * int param_2 = obj->pop();
 * int param_3 = obj->peek();
 * bool param_4 = obj->empty();
 */
var MyQueue = function() {
    this.queue = [];
};

/** 
 * @param {number} x
 * @return {void}
 */
MyQueue.prototype.push = function(x) {
    this.queue.push(x);
};

/**
 * @return {number}
 */
MyQueue.prototype.pop = function() {
    return this.queue.splice(0, 1);
};

/**
 * @return {number}
 */
MyQueue.prototype.peek = function() {
    return this.queue[0]
};

/**
 * @return {boolean}
 */
MyQueue.prototype.empty = function() {
    return this.queue.length === 0;
};

/** 
 * Your MyQueue object will be instantiated and called as such:
 * var obj = new MyQueue()
 * obj.push(x)
 * var param_2 = obj.pop()
 * var param_3 = obj.peek()
 * var param_4 = obj.empty()
 */
Implement Queue using Stacks