βœ…Lexographical Rotation (Contest)

Lexographical Rotation (Contest) easy Time Limit: 2 sec Memory Limit: 128000 kB

Problem Statement :

Given an array Arr of length N. Print the lexographically minimum rotation of the array Arr. All the elements of the array are distinct. Input First line of input contains a single integer N. Second line of input contains N integers denoting the array Arr.

Constraints: 1 <= N <= 100000 1 <= Arr[i] <= 1000000000 Output Print the lexographically minimum rotation of the array Arr. Example Sample Input 5 2 3 1 4 10

Sample Output 1 4 10 2 3

link:https://my.newtonschool.co/playground/code/cr2ncocq1owx

```java
import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework

// don't change the name of this class
// you can add inner classes if needed
class Main {
    public static void main (String[] args) {
        Scanner scan=new Scanner(System.in);
        int n= scan.nextInt();
        int[] arr=new int[n];
        for(int i=0;i<n;i++){
            arr[i] = scan.nextInt();
        }
        int minIndex=0;
        for(int i=1;i<n;i++){
            if(arr[i]<arr[minIndex]){
                minIndex=i;
            }
        }
        // Your code here
        for(int i=0;i<n;i++){
            System.out.print(arr[(i + minIndex)%n]+" ");
        }
    }
}
```

Last updated