Skip to content

Instantly share code, notes, and snippets.

@aw3s0me
Created July 20, 2017 21:45
Show Gist options
  • Select an option

  • Save aw3s0me/72f6ed07d59463534d7857ddec259faa to your computer and use it in GitHub Desktop.

Select an option

Save aw3s0me/72f6ed07d59463534d7857ddec259faa to your computer and use it in GitHub Desktop.
Hackerrank left shift
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 d = in.nextInt();
int a[] = new int[n];
int b[] = new int[n];
if (d < 1 || d > n) {
return;
}
if (n < 1 || n > Math.pow(10, 5)) {
return;
}
for(int a_i=0; a_i < n; a_i++){
a[a_i] = in.nextInt();
if (a[a_i] < 1 || a[a_i] > Math.pow(10, 6)) {
return;
}
}
int startIndex = Math.abs(n - d) % n;
for (int i = 0; i < n; i++) {
if (startIndex == n) {
startIndex = 0;
}
b[startIndex] = a[i];
startIndex++;
}
for (int i = 0; i < n; i++) {
System.out.print(b[i] + " ");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment