In this HackerRank Day 7 Arrays 30 days of code problem, we have Given an array, A, of N integers, print A's elements in reverse order as a single line of space-separated numbers.


hackerrank day 7 arrays 30 days of code solution


Problem solution in Python 2 programming.

#!/bin/python

import sys

n = int(raw_input().strip())
arr = map(int,raw_input().strip().split(' '))
for i in range(n):
    print arr[n-i-1],


Problem solution in Python 3 programming.

#!/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=' ')



Problem solution in java programming.

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] + " ");
        }
    }
}


Problem solution in c++ programming.

#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;
}


Problem solution in c programming.

#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;
}

Problem solution in Javascript programming.

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);

}