Posts Day07 - Arrays (Python 3)
Post
Cancel

Day07 - Arrays (Python 3)

  • URL : https://www.hackerrank.com/challenges/30-arrays/problem

  • Objective
    • Today, we’re learning about the Array data structure. Check out the Tutorial tab for learning materials and an instructional video!
  • Task
    • Given an array, A, of N integers, print A’s elements in reverse order as a single line of space-separated numbers.
  • Input Format

    • The first line contains an integer, N (the size of our array).
    • The second line contains space-separated integers describing array ‘s elements.
  • Constraints
    • 1 <= N <= 1000
    • 1 <= Ai <= 10000, where Ai is the ith integer in the array.
  • Output Format

    • Print the elements of array A in reverse order as a single line of space-separated numbers.
1
2
3
4
5
6
7
8
9
10
11
12
13
import math
import os
import random
import re
import sys



if __name__ == '__main__':
    n = int(input())
    arr = list(map(int, input().rstrip().split()))
    for i in range(len(arr)):
        print(arr[::-1][i], end = ' ')
1
2
3
4
5
 1
 1234


1234 
1
2
3
arr = [1,2,3,4]
for i in range(len(arr)):
    print(arr[::-1][i], end = ' ')
1
4 3 2 1 
This post is licensed under CC BY 4.0 by the author.