Skip to content

Instantly share code, notes, and snippets.

@JonathanLalou
Created June 23, 2021 16:25
Show Gist options
  • Select an option

  • Save JonathanLalou/dfb51642c18e6f9d2f5548cbb2a24a6a to your computer and use it in GitHub Desktop.

Select an option

Save JonathanLalou/dfb51642c18e6f9d2f5548cbb2a24a6a to your computer and use it in GitHub Desktop.
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
class Result {
/*
* Complete the 'rotLeft' function below.
*
* The function is expected to return an INTEGER_ARRAY.
* The function accepts following parameters:
* 1. INTEGER_ARRAY a
* 2. INTEGER d
*/
public static List<Integer> rotLeft(List<Integer> a, int d) {
final int size = a.size();
final List<Integer> answer = new ArrayList<>(size);
for(int i = 0; i < size; i++){
answer.add(a.get((i+d) % size));
}
return answer;
}
}
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
String[] firstMultipleInput = bufferedReader.readLine().replaceAll("\\s+$", "").split(" ");
int n = Integer.parseInt(firstMultipleInput[0]);
int d = Integer.parseInt(firstMultipleInput[1]);
List<Integer> a = Stream.of(bufferedReader.readLine().replaceAll("\\s+$", "").split(" "))
.map(Integer::parseInt)
.collect(toList());
List<Integer> result = Result.rotLeft(a, d);
bufferedWriter.write(
result.stream()
.map(Object::toString)
.collect(joining(" "))
+ "\n"
);
bufferedReader.close();
bufferedWriter.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment