Arrays | David Capella
View on GitHub

David Capella

Data Engineer




Given an array, A, of N integers, print A’s elements in reverse order as a single line of space-separated numbers. - HackerRank

Pseudo Code

# Reverse Array
# Turn array into a string
# Join array
# Print results


Reverse Array


Turn array into a string

[str(i) for i in arr[::-1]]

Join array

" ".join(str(i) for i in arr[::-1])
print(" ".join(str(i) for i in arr[::-1]))

Full Code


import math
import os
import random
import re
import sys

if __name__ == '__main__':
    n = int(input())

    arr = list(map(int, input().rstrip().split()))

    print(" ".join(str(i) for i in arr[::-1]))


Probably the most simple solution but still fun and a good reminder of how to reverse an array and turn it into a string while joining it.