Skip to content

Instantly share code, notes, and snippets.

@sanikamal
Created September 21, 2022 16:32
Show Gist options
  • Save sanikamal/40110a4ae6f8989b521aa6b5b73b76d0 to your computer and use it in GitHub Desktop.
Save sanikamal/40110a4ae6f8989b521aa6b5b73b76d0 to your computer and use it in GitHub Desktop.
Given an array, A, of N integers, print A's elements in reverse order as a single line of space-separated numbers.
public class Solution {
public static void print(String[] arr){
for(int i = arr.length - 1; i >= 0; i--){
System.out.print(arr[i] + " ");
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = Integer.parseInt(in.nextLine());
String[] arr = in.nextLine().split(" ");
in.close();
print(arr);
}
}
n = int(input().strip())
arr = list(map(int, input().rstrip().split()))
print(' '.join(str(i) for i in arr[::-1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment