

Input: Queries:
[ 1 2,
1 7,
2,
1 13,
2,
2,
2 ]
Output:
[ 2,
7,
13,
-1 ]
Explanation: After each operation, our queue is equal to the following:
1 2: {2}
1 7: {2, 7}
2: {7} and 2 is printed
1 13: {7, 13}
2: {13} and 7 is printed
2: {} and 13 is printed
2: {} and -1 is printed since the queue is empty.
The first line contains an integer ‘query’, the number of queries.
The next ‘query’ lines each contain a query.
If the first integer in the line is equal to 1, then it is an enqueue query and is followed by the integer 'e'.
Otherwise, if the first integer is equal to 2, then it is a dequeue query.
Solve the queries and print the appropriate dequeued values.
You need not consider the queries. You are given the structure of the queue. It consists of an array ‘a’ of size 100001 and 2 variables ‘rear’ and ‘front’, storing the index of the rear and the front elements, respectively. Both ‘rear’ and ‘front’ are initially equal to 0.
Implement the enqueue() and the dequeue() functions which add and retrieve the elements from the queue.
The elements currently in the queue are defined using the variables ‘rear’ and ‘front’.
When the array ‘a’ is empty, both ‘rear’ and ‘front’ are 0. This means the range of the queue can be defined from index ‘front’ to ‘rear’ - 1 (both inclusive).
This means there is an element in the queue if ‘front’ < ‘rear’. Therefore our queue is empty if ‘front’ >= ‘rear’. In our implementation, ‘front’ should never exceed ‘rear’. So the condition ‘front’ = ‘rear’ is sufficient for checking if the queue is empty.
For enqueue operation, place the element at ‘a[rear]’ and then increase ‘rear’ by 1.
For dequeue operation, check if the queue is empty. If it is not empty, return ‘a[front]’ and increase ‘front’ by 1. Don’t write the increase statement after the return statement, else it will become unreachable. Either store the value to be returned or use postfix increment.
Since the maximum value of ‘query’ is 10 ^ 5, and the given length of ‘a’ is more than 10 ^ 5, we can implement a simple queue. Otherwise, we can also implement a Circular Queue using the array. It has a fixed size, but we can use the entire array.
Ninja and his Birthday Treat
Rock Paper Scissor
Rock Paper Scissor
Rock Paper Scissor
Rock Paper Scissor
Longest Palindromic Substring
Find the direction from given string
Subarray Median Queries