Prefix Sum || C++
\n\n# Code\n\nclass Solution {\npublic:\n    int bestRotation(vector<int>& v) {\n        int n=v.size();\n        vector<int>t(n+2,0);\n        for(int i=0;i<v.
\n\n# Code\n```\nclass Solution {\npublic:\n    int bestRotation(vector<int>& v) {\n        int n=v.size();\n        vector<int>t(n+2,0);\n        for(int i=0;i<v.size();i++){\n            int start=v[i];\n            if(i<start){\n                int indistart=i+1;\n                int indiend=i+1+(n-1)-start;\n                t[indistart]++;\n                t[indiend+1]--;\n            }\n            else{\n                int indistart=0;\n                int indiend=i-start;\n                t[indistart]++;\n                t[indiend+1]--;\n                indistart=i+1;\n                indiend=n-1;\n                t[indistart]++;\n                t[indiend+1]--;\n            }\n        }\n        for(int i=1;i<=n+1;i++){\n            t[i]+=t[i-1];\n        }\n        int res=0;\n        int maxi=t[0];\n        for(int i=0;i<n;i++){\n            if(maxi<t[i]){\n                maxi=t[i];\n                res=i;\n            }\n        }\n        return res;\n    }\n};\n```
['C++']