Reverse a Queue Coding Question

Problem Statement:

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.

Input Format:

The first line input for each test case/query contains an integer N, denoting the total number of elements in the queue.

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.

Output Format:

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.

Output for every test case/query will be printed

on a new line.

Sample Input:

1 2 3 4 5 10


Here, 1 is at the front and 10 is at the rear of the queue.

Sample Output :

10 5 4 3 2 1


Thanks for Reading

Placewit grows the best engineers by providing an interactive classroom experience and by helping them develop their skills and get placed in amazing companies.

Learn more at Placewit. Follow us on Instagram and Facebook for daily learning.




Upskilling students for tech placements!

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Hacktoberfest inspiration: five reasons to participate in open source

GitHub action flow for publishing the Vs-code plugin

Everything About Stack Data Structure in Python

Build + Buy: How custom development adds value to COTS

Spring MVC(Model View Controller)

How to compare ’n’ number of flat lists in Python ?

8 Benefit Of Web Developing in 2021

Determining ingress host availability across Kubernetes clusters

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


Upskilling students for tech placements!

More from Medium

K Smallest Elements

Leetcode 142. Linked List Cycle II

Find the K-Beauty of a Number

How Meta helped me get into Google!