You are viewing a single comment's thread. Return to all comments →
Java solution using modular arithmetic:
public static List<Integer> circularArrayRotation(List<Integer> a, int k, List<Integer> queries) { int n = a.size(); int[] rotated = new int[n]; for (int i = 0; i < n; i++) { rotated[(i+k) % n] = a.get(i); } List<Integer> result = new ArrayList<>(); for (int q : queries) { result.add(rotated[q]); } return result; }
Seems like cookies are disabled on this browser, please enable them to open this website
Circular Array Rotation
You are viewing a single comment's thread. Return to all comments →
Java solution using modular arithmetic: