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:

6
1 2 3 4 5 10

Note:

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

Sample Output :

10 5 4 3 2 1

Code:

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

Oracle DB Transactions — Fuzzy read

Announcement About the Seventh Phase “Earn” of DIBI

input(),type conversion| python tutorial 3

Biopython to Retrieving Fasta Sequences From Ncbi Databases

Using SSD and Microservices to Optimize App Performance

Simplest Leaderboard Using Python

WEEEK Week #37: Task lists and notifications by time

without curation

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
Placewit

Placewit

Upskilling students for tech placements!

More from Medium

K Smallest Elements

73 — Set Matrix Zeroes

[Leetcode] Reverse Nodes in k-Group

Leetcode Series. No 435: Non-overlapping Intervals