In this Hackerrank Day 7 : Arrays 30 days of code solution .
Task
Given an array, A, of N integers, print A‘s elements in reverse order as a single line of space-separated numbers.
Example
A = [ 1,2,3,4]
Print 4 3 2 1. Each integer is separated by one space.
Input Format
The first line contains an integer,N (the size of our array).
The second line contains N space-separated integers that describe array ‘s elements.
Constraints
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.
Sample Input
4
1 4 3 2
Sample Output
2 3 4 1Hackerrank Day 7 : Arrays 30 days of code solution
Arrays HackerRank Solution in C
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
int main(){
int n,m=0;
scanf("%d",&n);
int *arr = malloc(sizeof(int) * n);
for(int arr_i = 0; arr_i < n; arr_i++){
scanf("%d",&arr[arr_i]);
}
for(int arr_j=n-1;arr_j >=0; arr_j--){
printf("%d ", arr[arr_j]);
}
return 0;
}Arrays HackerRank Solution in C ++
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
int main(){
int n;
cin >> n;
vector<int> arr(n);
for(int arr_i = 0;arr_i < n;arr_i++){
cin >> arr[arr_i];
}
for(int arr_i = n-1;arr_i >= 0;arr_i--){
cout << arr[arr_i] << " ";
}
cout << endl;
return 0;
}Arrays HackerRank Solution in Java
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] arr = new int[n];
for(int i=0; i < n; i++){
arr[i] = in.nextInt();
}
in.close();
for(int i = n - 1; i > -1; i--){
System.out.print(arr[i] + " ");
}
}
}Arrays HackerRank Solution in Python 3
#!/bin/python3
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 reversed(arr):
print(i,end=' ')Arrays HackerRank Solution in JavaScript
process.stdin.resume();
process.stdin.setEncoding('ascii');
var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;
process.stdin.on('data', function (data) {
input_stdin += data;
});
process.stdin.on('end', function () {
input_stdin_array = input_stdin.split("\n");
main();
});
function readLine() {
return input_stdin_array[input_currentline++];
}
/////////////// ignore above this line ////////////////////
function main() {
var n = parseInt(readLine());
arr = readLine().split(' ');
arr = arr.map(Number);
var printOut = '';
for (var i = arr.length -1; i >= 0; i--){
printOut = printOut + String(arr[i]) + ' ';
}
printOut = printOut.slice(0, printOut.length -1);
console.log(printOut);
}NEXT : Hackerrank Day 8 : Dictionaries and maps 30 days of code solution
30 Days of Code HackerRank Solutions List – Day 0 to Day 29
Read More –



