Arrays: Left Rotation

  • + 0 comments
    vector<int> rotLeft(vector<int> a, int d) {
        vector<int> b(a.size());
        
        for (int i = 0; i < a.size(); i++) {
            int newIndex = (i-d+a.size())%a.size();
            b[newIndex] = a[i];
        }
        
        
       
        return b;
    }