Skip to content

Instantly share code, notes, and snippets.

@marcgeld
Created November 23, 2016 11:48
Show Gist options
  • Save marcgeld/244be454c1d265d383cc55e0c6d9f4cd to your computer and use it in GitHub Desktop.
Save marcgeld/244be454c1d265d383cc55e0c6d9f4cd to your computer and use it in GitHub Desktop.
Hackerrank: Day 7: Arrays.groovy
/*
Objective
Today, we're learning 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.
Input Format
The first line contains an integer, (the size of our array).
The second line contains space-separated integers describing array 's elements.
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
*/
//Enter your code here. Read input from STDIN. Print output to STDOUT
System.in.eachLine() { line, rowid ->
if (rowid > 1)
line.split().reverseEach{ item ->
print "${item} "
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment