Skip to content

Instantly share code, notes, and snippets.

@MukulLatiyan
Created October 22, 2017 22:48
Show Gist options
  • Save MukulLatiyan/cd7747177e1621cf2a4ca849263bf23c to your computer and use it in GitHub Desktop.
Save MukulLatiyan/cd7747177e1621cf2a4ca849263bf23c to your computer and use it in GitHub Desktop.
Reversal Algorithm(GeeksForGeeks)
//Java Code for Reversal Algorithm problem solution given on geeksforgeeks array school section.
import java.util.*;
import java.lang.*;
import java.io.*;
class GFG {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int n = sc.nextInt();
for(int i=0;i<n;i++) {
int s=sc.nextInt();
int arr[] = new int[s];
for(int j=0;j<s;j++) {
arr[j]=sc.nextInt();
}
int d = sc.nextInt();
for(int l=0;l<s;l++) {
//shortest method,we can also use 2 for loop method.
System.out.print(arr[(l+d)%s]+" ");
}
System.out.println();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment