Greedy || Range sum || O(n)
Code\n\nclass Solution {\npublic:\n    int bestRotation(vector<int>& nums) {\n        int n = nums.size();\n        vector<int> fre(n+1,0);\n\n        for(int i
# Code\n```\nclass Solution {\npublic:\n    int bestRotation(vector<int>& nums) {\n        int n = nums.size();\n        vector<int> fre(n+1,0);\n\n        for(int i=0;i<n;i++) {\n            int l = nums[i] , r = n-1;\n            if(i >= l) {\n                int rl1 = 0 , rr1 = i-l;\n                fre[rl1]++;\n                fre[rr1+1]--;\n                int rl2 = i+1 , rr2 = n-1;\n                fre[rl2]++;\n                fre[rr2+1]--;\n                // cout << rl1 << " " << rr1 << "  " << rl2 << " " << rr2 << endl; \n            } else {\n                int rl = ((i-l)%n + n)%n , rr = ((i-r)%n + n)%n;\n                fre[rr]++;\n                fre[rl+1]--;\n                // cout << rl << " " << rr << endl;\n            }\n        }\n\n        for(int i=1;i<=n;i++) fre[i] += fre[i-1]; \n        // for(int i=0;i<n;i++) cout << fre[i] << " ";\n        int mf = 0 , k=0;\n        for(int i=0;i<n;i++) if(fre[i] > mf) mf = fre[i] , k = i;\n\n        return k;\n    }\n};\n```
['Greedy', 'C++']