This is my solution to challenge about Arrays left rotation. Click here to see the challenge.
import java.io.*;
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
int a[] = new int[n];
for(int a_i=0; a_i < n; a_i++){
a[a_i] = in.nextInt();
}
a = rotateLeft(a, k);
for(int a_i=0; a_i < n; a_i++){
System.out.print(a[a_i] + " ");
}
}
public static int[] rotateLeft(int array[] ,int n){
int[] new_array = new int[array.length];
for (int i =0; i < array.length; i++){
int new_index = (i < n) ? (array.length + (i-n)) : i -n;
new_array[new_index] = array[i];
}
return new_array;
}
}