In this HackerRank Day 7: Arrays problem solution 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 problem solution


Problem solution in Python programming.

#!/bin/python3

#import sys
#n = int(input().strip())
#arr = [int(arr_temp) for arr_temp in input().strip().split(' ')]

arraySize = int(input())
arrayOri = input().split()
arrayNew = []

while arraySize != len(arrayOri):
    arrayOri = input().split()

for i in range(arraySize-1, -1, -1):
    arrayNew.append(arrayOri[i])
    
for j in range(0, arraySize):
    print(arrayNew[j], 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();
        
        String message = "";
        for(int i = arr.length - 1; i >= 0; i--){
            message += arr[i] + " ";
        }
        
        message = message.trim();
        System.out.println(message);
    }
}




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 i(n-1); i >= 0; --i) {
        cout << arr[i] << " ";
    }
    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; 
    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_i = n-1;arr_i>=0;arr_i--)
    {
        printf("%d ", arr[arr_i]);
    }
    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);
    console.log(arr.reverse().join(' '))

}