Created
July 5, 2022 18:18
-
-
Save alwaisy/57e54cd5108d7b2cfe852d3e4fe76f08 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// problem | |
Objective | |
Today, we will learn about the Array data structure. Check out the Tutorial tab for learning materials and an instructional video. | |
Task | |
Given an array, , of integers, print 's elements in reverse order as a single line of space-separated numbers. | |
Example | |
Print 4 3 2 1. Each integer is separated by one space. | |
Input Format | |
The first line contains an integer, (the size of our array). | |
The second line contains space-separated integers that describe array 's elements. | |
Constraints | |
Constraints | |
, where is the integer in the array. | |
Output Format | |
Print the elements of array in reverse order as a single line of space-separated numbers. | |
Sample Input | |
4 | |
1 4 3 2 | |
Sample Output | |
2 3 4 1 | |
/** solution => 8 tests are passed*/ | |
'use strict'; | |
process.stdin.resume(); | |
process.stdin.setEncoding('utf-8'); | |
let inputString = ''; | |
let currentLine = 0; | |
process.stdin.on('data', function(inputStdin) { | |
inputString += inputStdin; | |
}); | |
process.stdin.on('end', function() { | |
inputString = inputString.split('\n'); | |
main(); | |
}); | |
function readLine() { | |
return inputString[currentLine++]; | |
} | |
function main() { | |
const n = parseInt(readLine().trim(), 10); | |
const arr = readLine().replace(/\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10)); | |
const reverseArr = arr.reverse() | |
const str = reverseArr.join(' ') | |
console.log(str) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment