Reverse a Queue

Quick Overview

Reverse a queue of integers, given as a front-to-back array, so that the old back becomes the new front. The problem tests how FIFO and LIFO ordering interact, using a stack as auxiliary storage, and keeping the work linear in the queue length.

Reverse a Queue

Company: MuleSoft

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

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 ```python 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 ```text 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. ```text 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. ```text Input: queue = [] Output: [] ``` There are no elements to move, so the result is empty.

Overview: Reverse a queue of integers, given as a front-to-back array, so that the old back becomes the new front. The problem tests how FIFO and LIFO ordering interact, using a stack as auxiliary storage, and keeping the work linear in the queue length.

MuleSoft logo
MuleSoft
Nov 25, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

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.