You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You have been given a queue that can store integers as the data. You are required to write a function that reverses the populated queue itself without using any other data structures.
2
+
Example:
3
+
Alt txt
4
+
5
+
Alt txt
6
+
7
+
Input Format:
8
+
The first list of input contains an integer 't' denoting the number of test cases/queries to be run.
9
+
Then the test cases follow.
10
+
11
+
The first line input for each test case/query contains an integer N, denoting the total number of elements in the queue.
12
+
13
+
The second line of input contains N integers separated by a single space, representing the order in which the elements are enqueued into the queue.
14
+
Output Format:
15
+
For each test case/query, the only line of output prints the order in which the queue elements are dequeued, all of them separated by a single space.
16
+
17
+
Output for every test case/query will be printed on a new line.
18
+
Note:
19
+
You are not required to print the expected output explicitly, it has already been taken care of. Just make the changes in the input queue itself.
20
+
Constraints:
21
+
1 <= t <= 100
22
+
1 <= N <= 10^4
23
+
-2^31 <= data <= 2^31 - 1
24
+
25
+
Time Limit: 1sec
26
+
Sample Input 1:
27
+
1
28
+
6
29
+
1 2 3 4 5 10
30
+
Note:
31
+
Here, 1 is at the front and 10 is at the rear of the queue.
0 commit comments