ret.add(A.get((i + B)%A.size()));
I think time complexity wise, because all elements in the array need to be moved (besides the case when b % len(a) == 0), O(N) time is optimal. However, this solution does use O(N) extra space. If you want to use O(1) extra space and solve it in place, you can rotate the array 3 times. First rotate a[0: b], then a[b: -1] and finally rotate whole array again.