We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Hi akueisara39 : i appreciate your code as it appears to be out of box solution . but i feel it throws an exception when the number of shift operations is greater than the size(d>n) of the array so just added few lines of code to it .
int[] array = new int[n];
if(d>n) d=d%n;
for(int i=0; i
array[(i+n-d)%n] = scan.nextInt();
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Left Rotation
You are viewing a single comment's thread. Return to all comments →
Hi akueisara39 : i appreciate your code as it appears to be out of box solution . but i feel it throws an exception when the number of shift operations is greater than the size(d>n) of the array so just added few lines of code to it .
int[] array = new int[n]; if(d>n) d=d%n; for(int i=0; i array[(i+n-d)%n] = scan.nextInt();
}