Arrays: Left Rotation

  • + 0 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;
    }