Java Collections | Set 9 (Queue)
Basic Accuracy: 40.73% Submissions: 971 Points: 1

Implement different operations on a queue q .

Input:
The first line of input contains an integer T denoting the no of test cases . Then T test cases follow. The first line of input contains an integer Q denoting the no of queries . Then in the next line are Q space separated queries .
A query can be of four types 
1. a x (Pushes an element x at the end of the queue q )
2. r (if queue is not empty pops the front element and prints it, else prints -1)
3. s (prints the size of the queue)
4. p (if queue is not empty prints the front element of the queue, else prints -1)

Output:
The output for each test case will  be space separated integers denoting the results of each query . 

Constraints:
1<=T<=100
1<=Q<=100

Example:

Input
2
5
a 5 a 10 a 15 r p
4
a 5 r p s 
 
Output:

5 10 
5 -1 0 

EXPLANATION:

In test case 1:  In first query 5 is added to the queue.In second query 10 is added to the queue. In third query 15 is added to the queue. In fourth query 5 is removed from the queue and printed.In last query front element of the queue is printed i.e. 10.

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.