Using sublists in Java


#1

We can use SubLists(Java) or slice(JS) for best possible solution.

public class Solution {
public ArrayList rotateArray(ArrayList A, int B) {
B = B < A.size() ? B : (B%A.size());
ArrayList ret = new ArrayList(A.subList(B, A.size()));
ret.addAll(A.subList(0, B));
return ret;
}
}