I tried to solve this Left Rotation problem on HackerRank. My code works out for most test cases, but for some it doesn't, probably because they have large umbernumber of data. So there seems to be some optimization or performance issue in my code, and I can't really figure out how to fix it. Any help will be greatly appreciated :)
public class Solution {
private static final Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
String[] nd = scanner.nextLine().split(" ");
int c;
int n = Integer.parseInt(nd[0]);
int d = Integer.parseInt(nd[1]);
int[] a = new int[n];
int arr[] = new int[n];
String[] aItems = scanner.nextLine().split(" ");
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
for (int i = 0; i < n; i++) {
int aItem = Integer.parseInt(aItems[i]);
a[i] = aItem;
}
scanner.close();
for (int k=1;k<=d;k++) {
for (int j=0;j<n;j++) {
if (j==n-1)
{ c=0;}
else
{ c=j+1;}
arr[j]=a[c];
}
System.arraycopy(arr, 0, a, 0, n);
}
for (int j=0;j<n;j++) {
System.out.print(arr[j]+ " ");
}
}
}