• + 1 comment

    I saw this problem in Steven Skiena's book, The Algorithm Design Manual. Below is my solution in C++:

    vector<int> rotateLeft(int d, vector<int> arr) {
        int n = arr.size();
    
        vector<int> a(n);
        for(int i=0; i<n; i++) {
            a[i] = arr[(i+d)%n];
        }
        
        return a;
    }