Sunday, March 6, 2022

HackerRank 30 day code challenge Day 7

 HackerRank 30 day code challenge Day 7

Problem:

Take input N this is the length of the array. Take input elements of the array of (length N). Elements are all integers. Print this array in reverse order on the same line and space separated.


import math
import os
import random
import re
import sys

n = int(input().strip())
arr=[]
arr = list(map(int, input().rstrip().split()))

i=len(arr)-1
#print(i)
while i<len(arr) and i>-1:
print(f'{arr[i]}' + " " ,end='')
i=i-1


Output:
6
1 2 3 4 5 6
6 5 4 3 2 1 
Process finished with exit code 0

No comments:

Post a Comment