An array A consisting of N integers is given. Rotation of the array means that each element is shifted right by one index, and the last element of the array is moved to the first place. For example, the rotation of array A = [3, 8, 9, 7, 6] is [6, 3, 8, 9, 7] (elements are shifted right by one index and 6 is moved to the first place).
The goal is to rotate array A K times; that is, each element of A will be shifted to the right K times.
Write a function:
class Solution { public int[] solution(int[] A, int K); }
that, given an array A consisting of N integers and an integer K, returns the array A rotated K times.
For example, given
A = [3, 8, 9, 7, 6] K = 3the function should return [9, 7, 6, 3, 8]. Three rotations were made:
[3, 8, 9, 7, 6] -> [6, 3, 8, 9, 7] [6, 3, 8, 9, 7] -> [7, 6, 3, 8, 9] [7, 6, 3, 8, 9] -> [9, 7, 6, 3, 8]For another example, given
A = [0, 0, 0] K = 1the function should return [0, 0, 0]
Given
A = [1, 2, 3, 4] K = 4the function should return [1, 2, 3, 4]
Assume that:
- N and K are integers within the range [0..100];
- each element of array A is an integer within the range [−1,000..1,000].
In your solution, focus on correctness. The performance of your solution will not be the focus of the assessment.
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> stack = new LinkedList<>();
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> stack = new LinkedList<>();
stack.
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> stack = new LinkedList<>();
stack.add()
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; )
queue.add();
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add();
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
System.out.print(queqe)
return new int[];
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
System.out.print(queue);
return new int[];
}
}
Solution.java:19: error: array dimension missing return new int[]; ^ 1 error
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
System.out.print(queue);
return 0;
}
}
Solution.java:19: error: incompatible types: int cannot be converted to int[] return 0; ^ 1 error
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
System.out.print(queue);
return A;
}
}
[6, 7, 9, 8, 3]
[0, 0, 0]
[4, 3, 2, 1]
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
System.out.print(queue.to);
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
System.out.print(queue.toString());
return A;
}
}
[6, 7, 9, 8, 3]
[0, 0, 0]
[4, 3, 2, 1]
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
System.out.print("print : " + queue.toString());
return A;
}
}
print : [6, 7, 9, 8, 3]
print : [0, 0, 0]
print : [4, 3, 2, 1]
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
System.out.print("print : " + queue.toString());
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; )
System.out.print("print : " + queue.toString());
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
}
System.out.print("print : " + queue.toString());
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
System.out.print("print : " + queue.toString());
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
// for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
// }
System.out.print("print : " + queue.toString());
return A;
}
}
print : [7, 9, 8, 3, 6]
print : [0, 0, 0]
print : [3, 2, 1, 4]
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
System.out.print("print : " + queue.toString());
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
System.out.print("print : " + queue.toString());
return A;
}
}
print : [8, 3, 6, 7, 9]
print : [0, 0, 0]
print : [4, 3, 2, 1]
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
System.out.print("print : " + queue.toString());
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
for
System.out.print("print : " + queue.toString());
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
for(int i=0; i<queue.size(); i++) {
}
System.out.print("print : " + queue.toString());
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[]
for(int i=0; i<queue.size(); i++) {
}
System.out.print("print : " + queue.toString());
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[A.length];
for(int i=0; i<queue.size(); i++) {
}
System.out.print("print : " + queue.toString());
return A;
}
}
print : [8, 3, 6, 7, 9]
print : [0, 0, 0]
print : [4, 3, 2, 1]
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[A.length];
for(int i=0; i<queue.size(); i++) {
B[i] = queue.poll;
}
System.out.print("print : " + queue.toString());
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[A.length];
for(int i=0; i<queue.size(); i++) {
B[i] = queue.poll();
}
System.out.print("print : " + queue.toString());
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[A.length];
for(int i=0; i<queue.size(); i++) {
B[i] = queue.poll();
}
System.out.println("print : " + queue.toString());
System.out.print("B : " + queue.toString());
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[A.length];
for(int i=0; i<queue.size(); i++) {
B[i] = queue.poll();
}
System.out.println("print : " + queue.toString());
System.out.print("B : " + B.toString());
return A;
}
}
print : [7, 9] B : [I@7d4991ad
print : [0] B : [I@7d4991ad
print : [2, 1] B : [I@7d4991ad
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[A.length];
for(int i=0; i<queue.size(); i++) {
B[i] = queue.poll();
}
System.out.println("print : " + queue.toString());
System.out.print("B : " + B);
return A;
}
}
print : [7, 9] B : [I@7d4991ad
print : [0] B : [I@7d4991ad
print : [2, 1] B : [I@7d4991ad
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[A.length];
for(int i=0; i<queue.size(); i++) {
System.out.print("B : " + B);
B[i] = queue.poll();
}
System.out.println("print : " + queue.toString());
System.out.print("B : " + B);
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[A.length];
for(int i=0; i<queue.size(); i++) {
System.out.print("B : " + B);
B[i] = queue.poll();
}
System.out.println("print : " + queue.toString());
System.out.print("B : " + B);
return A;
}
}
B : [I@7d4991adB : [I@7d4991adB : [I@7d4991adprint : [7, 9] B : [I@7d4991ad
B : [I@7d4991adB : [I@7d4991adprint : [0] B : [I@7d4991ad
B : [I@7d4991adB : [I@7d4991adprint : [2, 1] B : [I@7d4991ad
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[A.length];
for(int i=0; i<queue.size(); i++) {
System.out.println("Go");
B[i] = queue.poll();
}
System.out.println("print : " + queue.toString());
System.out.print("B : " + B);
return A;
}
}
Go Go Go print : [7, 9] B : [I@7d4991ad
Go Go print : [0] B : [I@7d4991ad
Go Go print : [2, 1] B : [I@7d4991ad
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[A.length];
for(int i=0; i<queue.size(); i++) {
B[i] = queue.poll();
}
System.out.println("print : " + queue.toString());
System.out.print("B : " + B);
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[A.length];
for(int i=0; i<queue.size(); i++) {
// B[i] = queue.poll();
}
System.out.println("print : " + queue.toString());
System.out.print("B : " + B);
return A;
}
}
print : [8, 3, 6, 7, 9] B : [I@7d4991ad
print : [0, 0, 0] B : [I@7d4991ad
print : [4, 3, 2, 1] B : [I@7d4991ad
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[A.length];
for(int i=0; i<queue.size(); i++) {
// B[i] = queue.poll();
}
System.out.println("print : " + queue.toString());
System.out.println("print : " + queue.toString());
System.out.print("B : " + B);
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[A.length];
for(int i=0; i<queue.size(); i++) {
// B[i] = queue.poll();
}
System.out.println("print : " + queue.size());
System.out.println("print : " + queue.toString());
System.out.print("B : " + B);
return A;
}
}
print : 5 print : [8, 3, 6, 7, 9] B : [I@7d4991ad
print : 3 print : [0, 0, 0] B : [I@7d4991ad
print : 4 print : [4, 3, 2, 1] B : [I@7d4991ad
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[A.length];
for(int i=0; i<queue.size(); i++) {
queue.poll();
}
System.out.println("print : " + queue.size());
System.out.println("print : " + queue.toString());
System.out.print("B : " + B);
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[A.length];
for(int i=0; i<queue.size(); i++) {
System.out.println("print : " + queue.poll());
}
// System.out.println("print : " + queue.size());
// System.out.println("print : " + queue.toString());
// System.out.print("B : " + B);
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[A.length];
for(int i=0; i<queue.size(); i++) {
System.out.println("print : " + queue.poll());
}
// System.out.println("print : " + queue.size());
// System.out.println("print : " + queue.toString());
// System.out.print("B : " + B);
return A;
}
}
print : 8 print : 3 print : 6
print : 0 print : 0
print : 4 print : 3
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[A.length];
for(int i=0; i<queue.size(); i++) {
// System.out.println("print : " + queue.poll());
}
// System.out.println("print : " + queue.size());
System.out.println("print : " + queue.toString());
// System.out.print("B : " + B);
return A;
}
}
print : [8, 3, 6, 7, 9]
print : [0, 0, 0]
print : [4, 3, 2, 1]
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[A.length];
for() {
// System.out.println("print : " + queue.poll());
}
// System.out.println("print : " + queue.size());
System.out.println("print : " + queue.toString());
// System.out.print("B : " + B);
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[A.length];
for(Integer i: queue) {
System.out.println("print : " + queue.poll());
}
// System.out.println("print : " + queue.size());
// System.out.println("print : " + queue.toString());
// System.out.print("B : " + B);
return A;
}
}
Exception in thread "main" java.util.ConcurrentModificationException at java.util.LinkedList$ListItr.checkForComodification(LinkedList.java:966) at java.util.LinkedList$ListItr.next(LinkedList.java:888) at Solution.solution(Solution.java:23) at Exec.run(exec.java:49) at Exec.main(exec.java:35)stdout:
print : 8
Exception in thread "main" java.util.ConcurrentModificationException at java.util.LinkedList$ListItr.checkForComodification(LinkedList.java:966) at java.util.LinkedList$ListItr.next(LinkedList.java:888) at Solution.solution(Solution.java:23) at Exec.run(exec.java:49) at Exec.main(exec.java:35)stdout:
print : 0
Exception in thread "main" java.util.ConcurrentModificationException at java.util.LinkedList$ListItr.checkForComodification(LinkedList.java:966) at java.util.LinkedList$ListItr.next(LinkedList.java:888) at Solution.solution(Solution.java:23) at Exec.run(exec.java:49) at Exec.main(exec.java:35)stdout:
print : 4
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[A.length];
for(int i=0; i<queue.size(); i++) {
// System.out.println("print : " + queue.poll());
}
// System.out.println("print : " + queue.size());
System.out.println("print : " + queue.toString());
// System.out.print("B : " + B);
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[A.length];
for(int i=0; i<queue.size(); i++) {
// System.out.println("print : " + queue.poll());
}
// System.out.println("print : " + queue.size());
System.out.println("print : " + queue.toString());
// System.out.print("B : " + B);
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[A.length];
for(int i=0; i<queue.size(); i++) {
// System.out.println("print : " + queue.poll());
}
// System.out.println("print : " + queue.size());
System.out.println("print : " + queue.toString());
// System.out.print("B : " + B);
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[A.length];
// for(int i=0; i<queue.size(); i++) {
// System.out.println("print : " + queue.poll());
// }
// System.out.println("print : " + queue.size());
System.out.println("print : " + queue.toString());
// System.out.print("B : " + B);
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[A.length];
for (Iterator<Integer> iter = queue.iterator(); iter.hasNext(); ) {
// for(int i=0; i<queue.size(); i++) {
// System.out.println("print : " + queue.poll());
// }
// System.out.println("print : " + queue.size());
System.out.println("print : " + queue.toString());
// System.out.print("B : " + B);
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[A.length];
for (Iterator<Integer> iter = queue.iterator(); iter.hasNext(); ) {
}
// for(int i=0; i<queue.size(); i++) {
// System.out.println("print : " + queue.poll());
// }
// System.out.println("print : " + queue.size());
System.out.println("print : " + queue.toString());
// System.out.print("B : " + B);
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[A.length];
for (Iterator<Integer> iter = queue.iterator(); iter.hasNext(); ) {
iter.next();
}
// for(int i=0; i<queue.size(); i++) {
// System.out.println("print : " + queue.poll());
// }
// System.out.println("print : " + queue.size());
System.out.println("print : " + queue.toString());
// System.out.print("B : " + B);
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[A.length];
for (Iterator<Queue<Integer>> iter = queue.iterator(); iter.hasNext(); ) {
iter.next();
}
// for(int i=0; i<queue.size(); i++) {
// System.out.println("print : " + queue.poll());
// }
// System.out.println("print : " + queue.size());
System.out.println("print : " + queue.toString());
// System.out.print("B : " + B);
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[A.length];
for (Iterator<Queue<Integer>> iter = queue.iterator(); iter.hasNext(); ) {
iter.next();
}
// for(int i=0; i<queue.size(); i++) {
// System.out.println("print : " + queue.poll());
// }
// System.out.println("print : " + queue.size());
System.out.println("print : " + queue.toString());
// System.out.print("B : " + B);
return A;
}
}
Solution.java:24: error: incompatible types: Iterator<Integer> cannot be converted to Iterator<Queue<Integer>> for (Iterator<Queue<Integer>> iter = queue.iterator(); iter.hasNext(); ) { ^ 1 error
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[A.length];
for (Iterator<Integer>> iter = queue.iterator(); iter.hasNext(); ) {
iter.next();
}
// for(int i=0; i<queue.size(); i++) {
// System.out.println("print : " + queue.poll());
// }
// System.out.println("print : " + queue.size());
System.out.println("print : " + queue.toString());
// System.out.print("B : " + B);
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[A.length];
for (Iterator<Integer> iter = queue.iterator(); iter.hasNext(); ) {
System.out.println(iter.next();
}
// for(int i=0; i<queue.size(); i++) {
// System.out.println("print : " + queue.poll());
// }
// System.out.println("print : " + queue.size());
System.out.println("print : " + queue.toString());
// System.out.print("B : " + B);
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[A.length];
for (Iterator<Integer> iter = queue.iterator(); iter.hasNext(); ) {
System.out.println("p:" + iter.next());
}
// for(int i=0; i<queue.size(); i++) {
// System.out.println("print : " + queue.poll());
// }
// System.out.println("print : " + queue.size());
System.out.println("print : " + queue.toString());
// System.out.print("B : " + B);
return A;
}
}
p:8 p:3 p:6 p:7 p:9 print : [8, 3, 6, 7, 9]
p:0 p:0 p:0 print : [0, 0, 0]
p:4 p:3 p:2 p:1 print : [4, 3, 2, 1]
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[A.length];
for (Iterator<Integer> iter = queue.iterator(); iter.hasNext(); ) {
System.out.println("p:" + iter.next());
}
// for(int i=0; i<queue.size(); i++) {
// System.out.println("print : " + queue.poll());
// }
// System.out.println("print : " + queue.size());
System.out.println("print : " + queue.toString());
// System.out.print("B : " + B);
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[A.length];
for (Iterator<Integer> iter = queue.iterator(); iter.hasNext(); ) {
System.out.println("p:" + iter.next());
B[]
}
// for(int i=0; i<queue.size(); i++) {
// System.out.println("print : " + queue.poll());
// }
// System.out.println("print : " + queue.size());
System.out.println("print : " + queue.toString());
// System.out.print("B : " + B);
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[A.length];
int index = 0;
for (Iterator<Integer> iter = queue.iterator(); iter.hasNext(); ) {
System.out.println("p:" + iter.next());
B[index] =
}
// for(int i=0; i<queue.size(); i++) {
// System.out.println("print : " + queue.poll());
// }
// System.out.println("print : " + queue.size());
System.out.println("print : " + queue.toString());
// System.out.print("B : " + B);
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[A.length];
int index = 0;
for (Iterator<Integer> iter = queue.iterator(); iter.hasNext(); ) {
System.out.println("p:" + iter.next());
B[index] = iter
}
// for(int i=0; i<queue.size(); i++) {
// System.out.println("print : " + queue.poll());
// }
// System.out.println("print : " + queue.size());
System.out.println("print : " + queue.toString());
// System.out.print("B : " + B);
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[A.length];
int index = 0;
for (Iterator<Integer> iter = queue.iterator(); iter.hasNext(); ) {
System.out.println("p:" + iter.next());
B[index] = iter.poll();
}
// for(int i=0; i<queue.size(); i++) {
// System.out.println("print : " + queue.poll());
// }
// System.out.println("print : " + queue.size());
System.out.println("print : " + queue.toString());
// System.out.print("B : " + B);
return A;
}
}
Solution.java:26: error: cannot find symbol B[index] = iter.poll(); ^ symbol: method poll() location: variable iter of type Iterator<Integer> 1 error
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
Queue<Integer> queue = new LinkedList<>();
for(int i=A.length-1; i>=0; i--) {
queue.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
int[] B = new int[A.length];
int index = 0;
for (Iterator<Integer> iter = queue.iterator(); iter.hasNext(); ) {
System.out.println("p:" + iter.next());
B[index] = iter.remove();
}
// for(int i=0; i<queue.size(); i++) {
// System.out.println("print : " + queue.poll());
// }
// System.out.println("print : " + queue.size());
System.out.println("print : " + queue.toString());
// System.out.print("B : " + B);
return A;
}
}
Solution.java:26: error: incompatible types: void cannot be converted to int B[index] = iter.remove(); ^ 1 error
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
// Queue<Integer> queue = new LinkedList<>();
// for(int i=A.length-1; i>=0; i--) {
// queue.add(A[i]);
// }
// for(int i=0; i<K; i++) {
// Integer pollInt = queue.poll();
// queue.add(pollInt);
// }
// int[] B = new int[A.length];
// int index = 0;
// for (Iterator<Integer> iter = queue.iterator(); iter.hasNext(); ) {
// System.out.println("p:" + iter.next());
// B[index] = iter.remove();
// }
// // for(int i=0; i<queue.size(); i++) {
// // System.out.println("print : " + queue.poll());
// // }
// // System.out.println("print : " + queue.size());
// System.out.println("print : " + queue.toString());
// // System.out.print("B : " + B);
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
ArrayList<Integer> arr = new ArrayList<>();
// Queue<Integer> queue = new LinkedList<>();
// for(int i=A.length-1; i>=0; i--) {
// queue.add(A[i]);
// }
// for(int i=0; i<K; i++) {
// Integer pollInt = queue.poll();
// queue.add(pollInt);
// }
// int[] B = new int[A.length];
// int index = 0;
// for (Iterator<Integer> iter = queue.iterator(); iter.hasNext(); ) {
// System.out.println("p:" + iter.next());
// B[index] = iter.remove();
// }
// // for(int i=0; i<queue.size(); i++) {
// // System.out.println("print : " + queue.poll());
// // }
// // System.out.println("print : " + queue.size());
// System.out.println("print : " + queue.toString());
// // System.out.print("B : " + B);
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
ArrayList<Integer> arr = new ArrayList<>();
for(int i=0; i<A.length; i++) {
queue.add(A[i]);
}
// Queue<Integer> queue = new LinkedList<>();
// for(int i=A.length-1; i>=0; i--) {
// queue.add(A[i]);
// }
// for(int i=0; i<K; i++) {
// Integer pollInt = queue.poll();
// queue.add(pollInt);
// }
// int[] B = new int[A.length];
// int index = 0;
// for (Iterator<Integer> iter = queue.iterator(); iter.hasNext(); ) {
// System.out.println("p:" + iter.next());
// B[index] = iter.remove();
// }
// // for(int i=0; i<queue.size(); i++) {
// // System.out.println("print : " + queue.poll());
// // }
// // System.out.println("print : " + queue.size());
// System.out.println("print : " + queue.toString());
// // System.out.print("B : " + B);
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
ArrayList<Integer> arr = new ArrayList<>();
for(int i=0; i<A.length; i++) {
arr.add(A[i]);
}
// Queue<Integer> queue = new LinkedList<>();
// for(int i=A.length-1; i>=0; i--) {
// queue.add(A[i]);
// }
// for(int i=0; i<K; i++) {
// Integer pollInt = queue.poll();
// queue.add(pollInt);
// }
// int[] B = new int[A.length];
// int index = 0;
// for (Iterator<Integer> iter = queue.iterator(); iter.hasNext(); ) {
// System.out.println("p:" + iter.next());
// B[index] = iter.remove();
// }
// // for(int i=0; i<queue.size(); i++) {
// // System.out.println("print : " + queue.poll());
// // }
// // System.out.println("print : " + queue.size());
// System.out.println("print : " + queue.toString());
// // System.out.print("B : " + B);
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
ArrayList<Integer> arr = new ArrayList<>();
for(int i=0; i<A.length; i++) {
arr.add(A[i]);
}
for(int i=0; i<K; i++) {
Integer pollInt = queue.poll();
queue.add(pollInt);
}
// Queue<Integer> queue = new LinkedList<>();
// for(int i=A.length-1; i>=0; i--) {
// queue.add(A[i]);
// }
// for(int i=0; i<K; i++) {
// Integer pollInt = queue.poll();
// queue.add(pollInt);
// }
// int[] B = new int[A.length];
// int index = 0;
// for (Iterator<Integer> iter = queue.iterator(); iter.hasNext(); ) {
// System.out.println("p:" + iter.next());
// B[index] = iter.remove();
// }
// // for(int i=0; i<queue.size(); i++) {
// // System.out.println("print : " + queue.poll());
// // }
// // System.out.println("print : " + queue.size());
// System.out.println("print : " + queue.toString());
// // System.out.print("B : " + B);
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
ArrayList<Integer> arr = new ArrayList<>();
for(int i=0; i<A.length; i++) {
arr.add(A[i]);
}
for(int i=0; i<K; i++) {
int temp = arr.get(arr.size()-1);
}
// Queue<Integer> queue = new LinkedList<>();
// for(int i=A.length-1; i>=0; i--) {
// queue.add(A[i]);
// }
// for(int i=0; i<K; i++) {
// Integer pollInt = queue.poll();
// queue.add(pollInt);
// }
// int[] B = new int[A.length];
// int index = 0;
// for (Iterator<Integer> iter = queue.iterator(); iter.hasNext(); ) {
// System.out.println("p:" + iter.next());
// B[index] = iter.remove();
// }
// // for(int i=0; i<queue.size(); i++) {
// // System.out.println("print : " + queue.poll());
// // }
// // System.out.println("print : " + queue.size());
// System.out.println("print : " + queue.toString());
// // System.out.print("B : " + B);
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
ArrayList<Integer> arr = new ArrayList<>();
for(int i=0; i<A.length; i++) {
arr.add(A[i]);
}
for(int i=0; i<K; i++) {
int temp = arr.get(arr.size()-1);
arr.add(0, temp);
}
// Queue<Integer> queue = new LinkedList<>();
// for(int i=A.length-1; i>=0; i--) {
// queue.add(A[i]);
// }
// for(int i=0; i<K; i++) {
// Integer pollInt = queue.poll();
// queue.add(pollInt);
// }
// int[] B = new int[A.length];
// int index = 0;
// for (Iterator<Integer> iter = queue.iterator(); iter.hasNext(); ) {
// System.out.println("p:" + iter.next());
// B[index] = iter.remove();
// }
// // for(int i=0; i<queue.size(); i++) {
// // System.out.println("print : " + queue.poll());
// // }
// // System.out.println("print : " + queue.size());
// System.out.println("print : " + queue.toString());
// // System.out.print("B : " + B);
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
ArrayList<Integer> arr = new ArrayList<>();
for(int i=0; i<A.length; i++) {
arr.add(A[i]);
}
for(int i=0; i<K; i++) {
int temp = arr.get(arr.size()-1);
arr.add(0, temp);
}
System.out.print("arr : " + arr.toString());
// Queue<Integer> queue = new LinkedList<>();
// for(int i=A.length-1; i>=0; i--) {
// queue.add(A[i]);
// }
// for(int i=0; i<K; i++) {
// Integer pollInt = queue.poll();
// queue.add(pollInt);
// }
// int[] B = new int[A.length];
// int index = 0;
// for (Iterator<Integer> iter = queue.iterator(); iter.hasNext(); ) {
// System.out.println("p:" + iter.next());
// B[index] = iter.remove();
// }
// // for(int i=0; i<queue.size(); i++) {
// // System.out.println("print : " + queue.poll());
// // }
// // System.out.println("print : " + queue.size());
// System.out.println("print : " + queue.toString());
// // System.out.print("B : " + B);
return A;
}
}
arr : [6, 6, 6, 3, 8, 9, 7, 6]
arr : [0, 0, 0, 0]
arr : [4, 4, 4, 4, 1, 2, 3, 4]
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
ArrayList<Integer> arr = new ArrayList<>();
for(int i=0; i<A.length; i++) {
arr.add(A[i]);
}
for(int i=0; i<K; i++) {
int temp = arr.get(arr.size()-1);
arr.add(0, temp);
}
System.out.print("arr : " + arr.toString());
// Queue<Integer> queue = new LinkedList<>();
// for(int i=A.length-1; i>=0; i--) {
// queue.add(A[i]);
// }
// for(int i=0; i<K; i++) {
// Integer pollInt = queue.poll();
// queue.add(pollInt);
// }
// int[] B = new int[A.length];
// int index = 0;
// for (Iterator<Integer> iter = queue.iterator(); iter.hasNext(); ) {
// System.out.println("p:" + iter.next());
// B[index] = iter.remove();
// }
// // for(int i=0; i<queue.size(); i++) {
// // System.out.println("print : " + queue.poll());
// // }
// // System.out.println("print : " + queue.size());
// System.out.println("print : " + queue.toString());
// // System.out.print("B : " + B);
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
ArrayList<Integer> arr = new ArrayList<>();
for(int i=0; i<A.length; i++) {
arr.add(A[i]);
}
for(int i=0; i<K; i++) {
int last = arr.size()-1;
int temp = arr.get(last);
arr.remove(last);
arr.add(0, temp);
}
System.out.print("arr : " + arr.toString());
// Queue<Integer> queue = new LinkedList<>();
// for(int i=A.length-1; i>=0; i--) {
// queue.add(A[i]);
// }
// for(int i=0; i<K; i++) {
// Integer pollInt = queue.poll();
// queue.add(pollInt);
// }
// int[] B = new int[A.length];
// int index = 0;
// for (Iterator<Integer> iter = queue.iterator(); iter.hasNext(); ) {
// System.out.println("p:" + iter.next());
// B[index] = iter.remove();
// }
// // for(int i=0; i<queue.size(); i++) {
// // System.out.println("print : " + queue.poll());
// // }
// // System.out.println("print : " + queue.size());
// System.out.println("print : " + queue.toString());
// // System.out.print("B : " + B);
return A;
}
}
arr : [9, 7, 6, 3, 8]
arr : [0, 0, 0]
arr : [1, 2, 3, 4]
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
ArrayList<Integer> arr = new ArrayList<>();
for(int i=0; i<A.length; i++) {
arr.add(A[i]);
}
for(int i=0; i<K; i++) {
int last = arr.size()-1;
int temp = arr.get(last);
arr.remove(last);
arr.add(0, temp);
}
System.out.print("arr : " + arr.toString());
// Queue<Integer> queue = new LinkedList<>();
// for(int i=A.length-1; i>=0; i--) {
// queue.add(A[i]);
// }
// for(int i=0; i<K; i++) {
// Integer pollInt = queue.poll();
// queue.add(pollInt);
// }
// int[] B = new int[A.length];
// int index = 0;
// for (Iterator<Integer> iter = queue.iterator(); iter.hasNext(); ) {
// System.out.println("p:" + iter.next());
// B[index] = iter.remove();
// }
// // for(int i=0; i<queue.size(); i++) {
// // System.out.println("print : " + queue.poll());
// // }
// // System.out.println("print : " + queue.size());
// System.out.println("print : " + queue.toString());
// // System.out.print("B : " + B);
return arr;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
ArrayList<Integer> arr = new ArrayList<>();
for(int i=0; i<A.length; i++) {
arr.add(A[i]);
}
for(int i=0; i<K; i++) {
int last = arr.size()-1;
int temp = arr.get(last);
arr.remove(last);
arr.add(0, temp);
}
for()
System.out.print("arr : " + arr.toString());
// Queue<Integer> queue = new LinkedList<>();
// for(int i=A.length-1; i>=0; i--) {
// queue.add(A[i]);
// }
// for(int i=0; i<K; i++) {
// Integer pollInt = queue.poll();
// queue.add(pollInt);
// }
// int[] B = new int[A.length];
// int index = 0;
// for (Iterator<Integer> iter = queue.iterator(); iter.hasNext(); ) {
// System.out.println("p:" + iter.next());
// B[index] = iter.remove();
// }
// // for(int i=0; i<queue.size(); i++) {
// // System.out.println("print : " + queue.poll());
// // }
// // System.out.println("print : " + queue.size());
// System.out.println("print : " + queue.toString());
// // System.out.print("B : " + B);
return arr;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
ArrayList<Integer> arr = new ArrayList<>();
for(int i=0; i<A.length; i++) {
arr.add(A[i]);
}
for(int i=0; i<K; i++) {
int last = arr.size()-1;
int temp = arr.get(last);
arr.remove(last);
arr.add(0, temp);
}
for(Integer i: arr) {
}
System.out.print("arr : " + arr.toString());
// Queue<Integer> queue = new LinkedList<>();
// for(int i=A.length-1; i>=0; i--) {
// queue.add(A[i]);
// }
// for(int i=0; i<K; i++) {
// Integer pollInt = queue.poll();
// queue.add(pollInt);
// }
// int[] B = new int[A.length];
// int index = 0;
// for (Iterator<Integer> iter = queue.iterator(); iter.hasNext(); ) {
// System.out.println("p:" + iter.next());
// B[index] = iter.remove();
// }
// // for(int i=0; i<queue.size(); i++) {
// // System.out.println("print : " + queue.poll());
// // }
// // System.out.println("print : " + queue.size());
// System.out.println("print : " + queue.toString());
// // System.out.print("B : " + B);
return arr;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
ArrayList<Integer> arr = new ArrayList<>();
for(int i=0; i<A.length; i++) {
arr.add(A[i]);
}
for(int i=0; i<K; i++) {
int last = arr.size()-1;
int temp = arr.get(last);
arr.remove(last);
arr.add(0, temp);
}
for(Integer i: arr) {
A[i] = i
}
System.out.print("arr : " + arr.toString());
// Queue<Integer> queue = new LinkedList<>();
// for(int i=A.length-1; i>=0; i--) {
// queue.add(A[i]);
// }
// for(int i=0; i<K; i++) {
// Integer pollInt = queue.poll();
// queue.add(pollInt);
// }
// int[] B = new int[A.length];
// int index = 0;
// for (Iterator<Integer> iter = queue.iterator(); iter.hasNext(); ) {
// System.out.println("p:" + iter.next());
// B[index] = iter.remove();
// }
// // for(int i=0; i<queue.size(); i++) {
// // System.out.println("print : " + queue.poll());
// // }
// // System.out.println("print : " + queue.size());
// System.out.println("print : " + queue.toString());
// // System.out.print("B : " + B);
return arr;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
ArrayList<Integer> arr = new ArrayList<>();
for(int i=0; i<A.length; i++) {
arr.add(A[i]);
}
for(int i=0; i<K; i++) {
int last = arr.size()-1;
int temp = arr.get(last);
arr.remove(last);
arr.add(0, temp);
}
for(int i=0; i<arr.size(); i++) {
A[i] = i
}
System.out.print("arr : " + arr.toString());
// Queue<Integer> queue = new LinkedList<>();
// for(int i=A.length-1; i>=0; i--) {
// queue.add(A[i]);
// }
// for(int i=0; i<K; i++) {
// Integer pollInt = queue.poll();
// queue.add(pollInt);
// }
// int[] B = new int[A.length];
// int index = 0;
// for (Iterator<Integer> iter = queue.iterator(); iter.hasNext(); ) {
// System.out.println("p:" + iter.next());
// B[index] = iter.remove();
// }
// // for(int i=0; i<queue.size(); i++) {
// // System.out.println("print : " + queue.poll());
// // }
// // System.out.println("print : " + queue.size());
// System.out.println("print : " + queue.toString());
// // System.out.print("B : " + B);
return arr;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
ArrayList<Integer> arr = new ArrayList<>();
for(int i=0; i<A.length; i++) {
arr.add(A[i]);
}
for(int i=0; i<K; i++) {
int last = arr.size()-1;
int temp = arr.get(last);
arr.remove(last);
arr.add(0, temp);
}
for(int i=0; i<arr.size(); i++) {
A[i] = arr.get(i);
}
System.out.print("arr : " + arr.toString());
// Queue<Integer> queue = new LinkedList<>();
// for(int i=A.length-1; i>=0; i--) {
// queue.add(A[i]);
// }
// for(int i=0; i<K; i++) {
// Integer pollInt = queue.poll();
// queue.add(pollInt);
// }
// int[] B = new int[A.length];
// int index = 0;
// for (Iterator<Integer> iter = queue.iterator(); iter.hasNext(); ) {
// System.out.println("p:" + iter.next());
// B[index] = iter.remove();
// }
// // for(int i=0; i<queue.size(); i++) {
// // System.out.println("print : " + queue.poll());
// // }
// // System.out.println("print : " + queue.size());
// System.out.println("print : " + queue.toString());
// // System.out.print("B : " + B);
return A;
}
}
arr : [9, 7, 6, 3, 8]
arr : [0, 0, 0]
arr : [1, 2, 3, 4]
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
ArrayList<Integer> arr = new ArrayList<>();
for(int i=0; i<A.length; i++) {
arr.add(A[i]);
}
for(int i=0; i<K; i++) {
int last = arr.size()-1;
int temp = arr.get(last);
arr.remove(last);
arr.add(0, temp);
}
for(int i=0; i<arr.size(); i++) {
A[i] = arr.get(i);
}
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
ArrayList<Integer> arr = new ArrayList<>();
for(int i=0; i<A.length; i++) {
arr.add(A[i]);
}
for(int i=0; i<K; i++) {
int last = arr.size()-1;
int temp = arr.get(last);
arr.remove(last);
arr.add(0, temp);
}
for(int i=0; i<arr.size(); i++) {
A[i] = arr.get(i);
}
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
ArrayList<Integer> arr = new ArrayList<>();
for(int i=0; i<A.length; i++) {
arr.add(A[i]);
}
for(int i=0; i<K; i++) {
int last = arr.size()-1;
int temp = arr.get(last);
arr.remove(last);
arr.add(0, temp);
}
for(int i=0; i<arr.size(); i++) {
A[i] = arr.get(i);
}
return A;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
ArrayList<Integer> arr = new ArrayList<>();
for(int i=0; i<A.length; i++) {
arr.add(A[i]);
}
for(int i=0; i<K; i++) {
int last = arr.size()-1;
int temp = arr.get(last);
arr.remove(last);
arr.add(0, temp);
}
for(int i=0; i<arr.size(); i++) {
A[i] = arr.get(i);
}
return A;
}
}
The following issues have been detected: runtime errors.
For example, for the input ([], 1) the solution terminated unexpectedly.
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1 at java.util.ArrayList.elementData(ArrayList.java:422) at java.util.ArrayList.get(ArrayList.java:435) at Solution.solution(Solution.java:18) at Exec.run(exec.java:49) at Exec.main(exec.java:35)