diff array
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n\n\nclass Solution {\npublic:\n    int bestRotation(vector<int>& a) {\n        int n = a.size();\n        vector<int> d(n+1,0);\n        for(int i=0;i<n;i++)\n        {\n            if(a[i]<=i)\n            {\n                // debug("nho");\n                //ko the dich\n                //dich tu 0->i-a[i]\n                int l = 0;\n                int r = i-a[i];\n                if(l<=r)\n                {\n                    d[l]++;\n                    d[r+1]--;\n                }\n                // debug(l,r);\n                //dich tu i+1-> n-1\n                l = i+1;\n                r = n-1;\n                if(l<=r)\n                {\n                    d[l]++;\n                    d[r+1]--;\n                }\n                // debug(l,r);\n            }\n            else\n            {\n                // debug("to");\n                //dich tu i+1-> i+n-a[i]\n                int l = i+1;\n                int r = i+n-a[i];\n                if(l<=r)\n                {\n                    d[l]++;\n                    d[r+1]--;\n                }\n                // debug(l,r);\n\n            }\n        }\n        // debug(d);\n        for(int i=1;i<n;i++)\n        {\n            d[i]+=d[i-1];\n        }\n        // debug(d);\n        int res = 0;\n        int ans = -1;\n        for(int i=0;i<n;i++)\n        {\n            if(d[i]>res)\n            {\n                res = d[i];\n                ans = i;\n            }\n        }\n        \n        return ans;\n    }\n};\n```
['C++']