C++
\nclass Solution {\npublic:\n    int bestRotation(vector<int>& nums) {\n        int n = nums.size();\n        vector<int> cnt(n+1, 0);\n\t\t// For each number a
```\nclass Solution {\npublic:\n    int bestRotation(vector<int>& nums) {\n        int n = nums.size();\n        vector<int> cnt(n+1, 0);\n\t\t// For each number a at index i. In order to be counted as one, we need to move the number to the range of index [a, n-1].\n\t\t// If the number is outside of this range, the count is 0.\n\t\t// The idea is to calculate the range of move. [a, b]. When a <= move <= b, number a at index i will be moved to a position between  [a, n-1]. \n        for(int i=0; i<n; ++i) {\n            int a = nums[i];\n            if(a <= i) {\n                cnt[0]++;\n                cnt[i-a+1]--;\n                if(i + 1 <= n-1) {\n                    cnt[i+1]++;\n                    cnt[n]--;\n                }\n            } else {\n                if(i + 1 <= n + i - a) {\n                    cnt[i+1]++;\n                    cnt[n+i-a+1]--;\n                }\n            }\n        }\n        \n        int ans = 0, mx = 0, cur = 0;\n        for(int k=0; k<n; k++) {\n            cur += cnt[k];\n            if(cur > mx) {\n                ans = k;\n                mx = cur;\n            }\n        }\n        return ans;\n    }\n};\n```
[]