Sequence Reverser
EasyPractice library · +10 XPqueuedequesimulation
Given a sequence of N integers, print the elements in reverse order. Use a deque (double-ended queue) for this task.
Input
The first line contains an integer N (1 <= N <= 1000). The second line contains N space-separated integers.
Output
Print the N integers in reverse order, separated by spaces.
Constraints
1 <= N <= 1000. Each integer is between -1000 and 1000.
Time limit 1 s (native code; slower languages get more)Memory 256 MB12 hidden tests
Example 1
Input
5 1 2 3 4 5
Output
5 4 3 2 1
The input sequence 1 2 3 4 5 is reversed to 5 4 3 2 1.
Example 2
Input
3 10 -5 20
Output
20 -5 10
The sequence with negative numbers is also reversed correctly.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
Example 1 input
5 1 2 3 4 5
Example 2 input
3 10 -5 20