Given a queue of integers represented as an array queue in FIFO order (front to back), reverse the order of its elements so that the original back of the queue becomes the new front.
Return the reversed queue as an array, where the first element is the new front of the queue.
Function Signature
def reverse_queue(queue: list[int]) -> list[int]:
Rules
-
queue[0]
is the front of the queue and
queue[-1]
is the back. The returned list uses the same encoding.
-
An empty queue reverses to an empty list.
Constraints
-
0 <= len(queue) <= 10^4
-
-10^9 <= queue[i] <= 10^9
Examples
Input: queue = [1,2,3,4,5]
Output: [5,4,3,2,1]
The front of the queue is 1 and the back is 5. After reversing, the new front is 5 and the new back is 1.
Input: queue = [10,20,30]
Output: [30,20,10]
The last element, 30, is now at the front, and the order of the rest is flipped with it.
Input: queue = []
Output: []
There are no elements to move, so the result is empty.