• + 0 comments

    Here is my c++ solution, you can have the video explanation here : https://youtu.be/lyUDSB4Sg7Y

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