You are viewing a single comment's thread. Return to all comments →
public static List rotLeft(List a, int d) { // Write your code here int n = a.size(); d = d % n; // Handle cases where d > n
// Use sublists to rearrange in O(n) time List<Integer> rotated = new ArrayList<>(a.subList(d, n)); rotated.addAll(a.subList(0, d)); return rotated; }
Seems like cookies are disabled on this browser, please enable them to open this website
Arrays: Left Rotation
You are viewing a single comment's thread. Return to all comments →
public static List rotLeft(List a, int d) { // Write your code here int n = a.size(); d = d % n; // Handle cases where d > n