| Topic | Difficulty | Companies |
|---|---|---|
| Stack and Queue | EASY | Facebook Amazon Microsoft |
Implement the following operations of a queue using stacks.
Problem Note
Example
NewQueue queue = new NewQueue();
queue.enqueue(5);
queue.enqueue(10);
queue.peek(); // returns 5
queue.dequeue(); // returns 5
queue.empty(); // returns false
Input Format:
First-line contains N, the total number of queries.
Each of the following N lines have a query of any of the 4 types, type 1(enqueue), type 2(dequeue), type 3(peek), type 4(empty).
Query for type 1 is of format: 1 v, where v is value
Query for type 2, 3 and 4 just mention the query type
For example, the input for the above example will be:
5
1 5
1 10
3
2
4