An array is a type of data structure that stores elements of the same type in a contiguous block of memory. In an array, $A$, of size $N$, each memory location has some unique index, $i$ (where $0\leq i<N$), that can be referenced as $A[i]$ or $A_i$.

Reverse an array of integers.  

Note: If you've already solved our C++ domain's Arrays Introduction challenge, you may want to skip this.

Example 

$A=[1,2,3]$  

Return $[3,2,1]$.  

Function Description  

Complete the function reverseArray in the editor below.  

reverseArray has the following parameter(s):  

int A[n]: the array to reverse  

Returns  

int[n]: the reversed array

Input Format

The first line contains an integer, $N$, the number of integers in $A$. 

The second line contains $N$ space-separated integers that make up $A$.

Constraints

$1\leq N\leq10^3$
$1\leq A[i]\leq10^4,$where $A\begin{bmatrix}i\end{bmatrix}$ is the $i^{t h}$ integer in A

Source: hackerrank | Difficulty: EASY
Tags: Data structures


Solutions:
n = int(input())
m = input().strip().split(' ')
res = m[::-1]
r = ''
for i in range(n):
	r = r + str(res[i]) + ' '
print(r)


count = input()
inpt = input()
array = inpt.split(' ')
array = [i for i in array if len(i)]
array.reverse()
for i in array:
	print(i, end=' ')


n = int(input())
arr = input().split()

def print_reverse(arr):
	string = ''
	for i in range(len(arr)):
		string += arr[len(arr) - 1 - i] + ' '
	print(string.strip())
print_reverse(arr)


n = int(input())
inp = [int(x) for x in input().split()]
for i in range(n):
	print(inp[n - 1 - i], end=' ')


N = int(input())
Array = input()
Array = Array.split()
Array.reverse()
print(' '.join(Array))


n = input()
j = input().split()
for i in range(len(j) - 1, -1, -1):
	print(j[i], end=' ')


input()
for i in reversed(list(map(int, input().split()))):
	print(i, end=' ')
print()


input()
print(' '.join(reversed(input().split())))


input()
for elem in reversed(input().split()):
	print(elem, end=' ')


size = int(input())
arr = input().split()
print(' '.join([i for i in arr[::-1]]))


length = int(input())
string = input().split()
for num in reversed(string):
	print(num, end=' ')


n = int(input())
l = [int(x) for x in input().strip().split()]
print(*l[::-1])


input()
print(' '.join(input().split()[::-1]))


_ = input()
a = input().split()
print(' '.join(a[::-1]))


import sys
no_int = sys.stdin.readline().rstrip()
print(' '.join(sys.stdin.readline().rstrip().split()[::-1]))


n = int(input())
l = list(map(int, input().split()))
s = ''
for i in l:
	s = str(i) + ' ' + s
print(s.strip())


def main():
	num_input = int(input())
	arr = input().split()
	arr = [int(i) for i in arr]
	for i in range(num_input - 1, -1, -1):
		print(str(arr[i]) + ' ', end='')
main()


cases = int(input())
caseList = input().split()
reverseList = [caseList[-x] for x in range(1, cases + 1)]
print(' '.join(reverseList))


input()
lst = input()
lst = lst.split()[::-1]
print(' '.join(lst))


i = int(input())
a = input().replace('\n', '').replace('\t', '').strip().split(' ')
a.reverse()
for l in a:
	print(l, end=' ')


a = input()
print(' '.join(list(reversed(input().split()))))


number = input()
line = input().split()
print(' '.join(line[::-1]))


def prettyPrint(array):
	l = [str(i) for i in array]
	print(' '.join(l))

def reverse(array):
	n = len(array)
	result = []
	for i in range(n):
		result.append(array[n - 1 - i])
	return result
N = input()
array = [int(i) for i in input().split()]
prettyPrint(reverse(array))


import sys
num = int(sys.stdin.readline())
arr = sys.stdin.readline().split()
for elem in arr[::-1]:
	print(elem, end=' ')


N = int(input())
arr = list(input().split())
arr2 = []
for i in range(N - 1, -1, -1):
	arr2.append(arr[i])
print(' '.join(arr2))


_ = int(input())
nums = list(map(int, input().split()))
for x in nums[::-1]:
	print(x, end=' ')


N = int(input())
l = list(map(int, input().split()))
l.reverse()
print(*l)


x = int(input())
l = list(map(int, input().split()))
x = len(l)
while x > 0:
	print(l[x - 1], end=' ')
	x -= 1


input()
print(' '.join(input().split()[::-1]))


n = int(input())
array = input().split()
for i in range(len(array) - 1, -1, -1):
	print(array[i], end=' ')


num = int(input())
l = input().split()
for x in range(len(l)):
	print(l[len(l) - x - 1], end=' ')


def flip():
	N = int(input())
	A = input().split()
	for x in range(len(A) // 2):
		tempA = A[-(x + 1)]
		A[-(x + 1)] = A[x]
		A[x] = tempA
	out = ''
	for x in range(len(A) - 1):
		out += A[x] + ' '
	return out + A[-1]
print(flip())


import sys
count = int(input())
content = input()
array = content.split()
for i in range(count):
	print(array[count - 1 - i], end='')
	print(' ', end='')


input()
l = list(map(int, input().split()))
print(*reversed(l), sep=' ')


n = int(input())
myArray1 = input().split()
myArray2 = [0] * n
for i in range(0, n):
	myArray2[n - i - 1] = int(myArray1[i])
print(' '.join(map(str, myArray2)))


n = int(input())
ss = input().split()
aa = ss[::-1]
result = ''
for i in range(n):
	result += aa[i] + ' '
print(result)


input()
print(' '.join(reversed(input().strip().split(' '))))


n = int(input())
a = [0] * 10000
a = list(map(int, input().split()))
for i in range(len(a)):
	print(a[len(a) - 1 - i], end=' ')


input()
print(' '.join(input().split()[::-1]))


n = int(input())
arr = input().split()
toPrint = ''
for i in range(0, n):
	toPrint = toPrint + arr[n - i - 1] + ' '
print(toPrint)


n = int(input())
int_array = input().split()
print(' '.join(reversed(int_array)))


n = int(input())
array = [x for x in input().split()[:n]]
array.reverse()
for x in array:
	print(x + ' ', end='')


N = int(input())
List = input().split()
for i in range(N - 1, -1, -1):
	print(List[i], end=' ')


t = int(input())
l1 = list(map(int, input().split()))
l1 = l1[::-1]
print(*l1, sep=' ')


import sys
n = int(sys.stdin.readline())
mat = sys.stdin.readline()
mat = mat.split()
for i in range(0, n):
	print(mat[n - 1 - i], end=' ')


N = int(input())
L = input().split()
i = len(L) - 1
while i >= 0:
	print(int(L[i]), end=' ', flush=True)
	i -= 1
print()


input()
a = list(map(int, input().split()))
for x in range(len(a) - 1, -1, -1):
	print(a[x], end=' ')


input()
print(' '.join(list(reversed(input().split()))))


N = int(input())
A = [int(i) for i in input().split()]
for i in A[::-1]:
	print(i, end=' ')


length = input()
array = input()
array = array.split(' ')
array = [int(x) for x in array if x != '']
array = array[::-1]
for x in array:
	print(x, end=' ')
print('')


n = int(input())
print(' '.join(list(reversed(input().split()))))


N = int(input())
nums = input().split()
nums.reverse()
print(' '.join(nums))


import sys

def reverse(input):
	length = input[0]
	array = input[1:][0].split()
	reversedArray = ''
	for i in range(int(length)):
		reversedArray += array[int(length) - i - 1] + ' '
	return reversedArray

def main():
	input = sys.stdin.readlines()
	reversedArray = reverse(input)
	print(reversedArray)
main()


N = int(input())
tableau = [0] * N
t = input()
x = t.split()
for i in range(N):
	print(int(x[N - 1 - i]), end=' ')


N = int(input())
A = [str(i) for i in input().split()]
print(' '.join(A[::-1]))


input()
a = [x for x in input().strip().split(' ')]
a.reverse()
print(' '.join(a))


n = int(input())
nums = input().split()
nums.reverse()
NumsString = ' '.join(nums)
print(NumsString)


input()
[print(x, end=' ') for x in input().split()[::-1]]


n = int(input())
arr = input().split()
arr = [int(x) for x in arr]
l = len(arr)
for i in range(len(arr)):
	print(str(arr[l - (i + 1)]) + ' ', end='')


n = int(input())
string = ''
for s in input().split():
	string = s + ' ' + string
print(string)


def readInput():
	input()
	return [int(s) for s in input().strip().split(' ')]

def printReverse(list):
	print(' '.join((str(i) for i in reversed(list))))
printReverse(readInput())


import sys
n = input()
array = list(map(int, input().split()))
array.reverse()
for val in array:
	sys.stdout.write(str(val) + ' ')


i = int(input())
a = input().split()
a.reverse()
print(' '.join(a))


N = int(input())
a = list(map(int, input().split()))
a.reverse()
for i in a:
	print(i, end=' ')


n = int(input())
print(' '.join([str(x) for x in reversed(list(map(int, input().split())))]))


import fileinput
with fileinput.input() as f:
	n_nums = int(f.readline())
	nums_line = f.readline()
nums = nums_line.rstrip().split(' ')
out = ''
for i in reversed(range(0, n_nums, 1)):
	out += nums[i] + ' '
print(out)


n = int(input('').strip())
data_list = input('').strip().split(sep=' ')
i = n - 1
while i > 0:
	print(data_list[i] + ' ', end='')
	i -= 1
print(data_list[0])


x = int(input())
y = input().split()
y.reverse()
str = ''
for i in range(len(y)):
	str += y[i] + ' '
str.strip()
print(str)


size = int(input())
if size >= 1 and size <= 1000:
	data = input().split()
	for item in reversed(data):
		print(item, end=' ')


import sys
for line in sys.stdin:
	l = [int(elem) for elem in line.split()]
for e in reversed(l):
	print(e, end=' ')


n = int(input())
data = list(map(int, input().split()))
print(*reversed(data))


import sys
num = int(sys.stdin.readline().strip('\n'))
data = sys.stdin.readline().strip().split()
for i in range(num):
	print(data[num - i - 1], end=' ')


total_integer = input()
input_array = input()
input_array = input_array.strip().split()
print(' '.join(input_array[::-1]))
print('\n')


n = int(input())
arr = input().split(' ')

def printReverse(n, arr):
	arr = arr[::-1]
	revstr = ' '.join(arr)
	print(revstr.strip())
printReverse(n, arr)


n = int(input())
[print(int(x), end=' ') for x in reversed(str.split(input()))]


N = int(input())
arr = input().split()
print(' '.join(arr[::-1]))


input()
l = input().split()
for i in range(len(l) - 1, -1, -1):
	print(l[i], end=' ')


cases = input()
numbers = ' '.join(list(reversed(input().strip().split(' '))))
print(numbers)


N = int(input())
l = list(map(int, input().split()))
n_l = l[::-1]
result = ''
for i in n_l:
	result += str(i) + ' '
print(result)


len = input()
ls = input().split()
for i in ls[::-1]:
	print(i, end=' ')


import sys
n = sys.stdin.readline().strip()
a = sys.stdin.readline().strip().split(' ')
if int(n) > 0:
	print(' '.join(a[::-1]))


import fileinput
lines = []
for line in fileinput.input():
	lines += [line]
out = lines[1].strip().split(' ')
print(' '.join(out[::-1]))


input()
print(' '.join((sn for sn in reversed(input().strip().split(' ')))))


import sys
n = int(sys.stdin.readline())
a = [int(i) for i in sys.stdin.readline().split()][:n]
for i in a[::-1]:
	print(i, end=' ')


n = int(input())
i = n - 1
num = input().split()
x = []
while i >= 0:
	x.append(int(num[i]))
	i -= 1
string = ''
for j in x:
	string += str(j) + ' '
print(string)


n = int(input())
numbers_str = input()
numbers = list(map(int, numbers_str.split()))
numbers = numbers[:n]
for number in numbers[::-1]:
	print(number, end=' ')


input()
print(' '.join(reversed(input().strip().split(' '))))


x = input()
array = input().split()
newArray = []
for i in reversed(array):
	newArray.append(i)
space = ' '
print(' '.join([str(elem) for elem in newArray]))


n = int(input())
arr = [int(s) for s in input().split()]
for i in range(n - 1, -1, -1):
	print('{} '.format(arr[i]), end='')


input()
myList = [int(x) for x in input().split()]
print(' '.join([str(x) for x in myList[::-1]]))


size = int(input())
xs = list(map(int, input().split()))[::-1]
for x in xs:
	print(x, end=' ')


n = int(input())
numbers = input().split()
revNum = ''
for i in range(n - 1, -1, -1):
	revNum += numbers[i] + ' '
print(revNum)


N = int(input())
a = list(map(int, input().strip().split(' ')))
a.reverse()
print(*a, sep=' ')


def main():
	l = eval(input())
	ele = input().split(' ')
	if ele[len(ele) - 1] == '':
		ele.pop()
	l = len(ele)
	for i in range(l):
		j = l - i - 1
		if j == 0:
			print(ele[0])
			break
		else:
			print(ele[j], end=' ')
main()


_ = input()
arr = [int(x) for x in input().split()][::-1]
for i in arr[0:len(arr) - 1]:
	print(i, end=' ')
print(arr[-1])


n = int(input())
print(' '.join(input().split()[::-1]))


n = int(input())
myList = input().split()
myList.reverse()
for i in range(0, n - 1):
	print(int(myList[i]), end=' ')
print(int(myList[n - 1]))


int(input())
l = list(map(int, input().split()))
l.reverse()
for each in range(len(l)):
	print(l[each], end=' ')