Created
October 22, 2017 22:48
-
-
Save MukulLatiyan/cd7747177e1621cf2a4ca849263bf23c to your computer and use it in GitHub Desktop.
Reversal Algorithm(GeeksForGeeks)
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
//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