O(N) Line sweep
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```\nclass Solution {\npublic:\n    int bestRotation(vector<int>& nums) {\n        \n        vector<int>vk(nums.size()+3,0);\n        for(int i=0; i<nums.size(); i++){\n            if(nums[i]>i ){\n                vk[i+1]+=1;\n                vk[i+1 + ((nums.size()-1) - (nums[i]) +1)]-=1;\n            }\n            else if(nums[i]<=i){\n                vk[0]+=1;\n                vk[i-nums[i]+1]-=1;\n                vk[i+1]+=1;\n                vk[nums.size()] -=1;\n            }\n        }\nint maxi=INT_MIN,sum=0,ans=-1;\n        for(int i=0; i<nums.size(); i++){\n            sum+=vk[i];\n           if(maxi<sum){\n               maxi=sum;\n               ans=i;\n           }\n        }\n        return ans;\n    }\n};\n```
['Prefix Sum', 'C++']