|
| 1 | +package LoveBabbarDSA;// { Driver Code Starts |
| 2 | +//Initial Template for Java |
| 3 | + |
| 4 | +import java.lang.*; |
| 5 | +import java.io.*; |
| 6 | + |
| 7 | +class CyicallyRotateAnArray { |
| 8 | + public static void main(String[] args) throws IOException |
| 9 | + { |
| 10 | + BufferedReader br = |
| 11 | + new BufferedReader(new InputStreamReader(System.in)); |
| 12 | + int t = |
| 13 | + Integer.parseInt(br.readLine().trim()); // Inputting the testcases |
| 14 | + while(t-->0) |
| 15 | + { |
| 16 | + int n = Integer.parseInt(br.readLine().trim()); |
| 17 | + int a[] = new int[n]; |
| 18 | + // long getAnswer[] = new long[(int)(n)]; |
| 19 | + String inputLine[] = br.readLine().trim().split(" "); |
| 20 | + for (int i = 0; i < n; i++) { |
| 21 | + a[i] = Integer.parseInt(inputLine[i]); |
| 22 | + } |
| 23 | + |
| 24 | + Compute obj = new Compute(); |
| 25 | + obj.rotate(a, n); |
| 26 | + |
| 27 | + StringBuilder output = new StringBuilder(); |
| 28 | + for(int i=0;i<n;i++) |
| 29 | + output.append(a[i]+" "); |
| 30 | + System.out.println(output); |
| 31 | + |
| 32 | + } |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +// } Driver Code Ends |
| 37 | + |
| 38 | + |
| 39 | +//User function Template for Java |
| 40 | + |
| 41 | +class Compute { |
| 42 | + |
| 43 | + public void rotate(int arr[], int n) |
| 44 | + { |
| 45 | + int t = arr[n - 1]; |
| 46 | + for (int i = n - 1;i > 0;i--) { |
| 47 | + // int c = arr[i]; |
| 48 | + arr[i] = arr[i - 1]; |
| 49 | + } |
| 50 | + arr[0] = t; |
| 51 | + } |
| 52 | +} |
0 commit comments