New update is available. Click here to update.
Close
Topic list
Reversing Queue
EASY
15 mins
3 upvotes
Stacks & Queues
Arrays
Topics (Covered in this problem)
Problem solved
Skill meter
Stacks & Queues
-
Arrays
-
Other topics
Problem solved
Skill meter
Strings
-
Matrices (2D Arrays)
-
Sorting
-
Binary Search
-
Linked List
-
Trees
-
Graph
-
Dynamic Programming
-
Greedy
-
Tries
-
Binary Search Trees
-
Heap
-
Bit Manipulation
-

# Reversing Queue

Contributed by
Priyaraj
Easy
Avg time to solve 15 mins
Success Rate 85 %
Share
3 upvotes

## Problem Statement

#### You have been given a queue of ‘N’ distinct integers. For a given queue, you need to reverse all the elements in it.

##### Note:
``````You need to reverse the string in O(N) time complexity.
``````
Detailed explanation ( Input/output format, Notes, Constraints, Images )
##### Sample Input 1:
``````2
3
2 3 1
5
6 8 9 2 3
``````
##### Sample Output 1:
``````1 3 2
3 2 9 8 6
``````
##### Explanation For Sample Input 1:
``````In the first test case, after reversing the queue, the resultant elements of the reversed queue will be 1 3 2.

In the second test case, after reversing the queue, the resultant elements of the reversed queue will be 3 2 9 8 6.
``````
##### Sample Input 2:
``````2
7
6 8 9 11 15 2 3
4
1 2 3 4
``````
##### Sample Output 2:
``````3 2 15 11 9 8 6
4 3 2 1
``````
##### Explanation For Sample Input 2:
``````In the first test case, after reversing the queue, the resultant elements of the reversed queue will be 3 2 15 11 9 8 6.

In the second test case, after reversing the queue, the resultant elements of the reversed queue will be 4 3 2 1.
``````
Console