All problems

Problem 3

Reverse Array

Easy · 10 pts · Array, Two Pointers

Problem

You are given an array of N integers. Print the same elements in reverse order: the last element first, then the second-to-last, and so on until the first element. You can either build a new reversed array or swap elements in place from both ends towards the middle (swap the first with the last, the second with the second-to-last, and so on). Either way, every element is printed exactly once.

Input

First line: integer N. Second line: N space-separated integers.

Output

Print the reversed array as space-separated integers.

Constraints

1 <= N <= 100000; -1000000000 <= array[i] <= 1000000000

Example input

5
1 2 3 4 5

Example output

5 4 3 2 1

Explanation

The array is 1 2 3 4 5. Reading it from the last element back to the first gives 5 4 3 2 1.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Two Sum Next: Palindrome Check