C++ | Explanation | Line Sweep
Explanation\n1. For any nums[i] how many shifts are required to get one point ??\n2. Low and high are min and max shifts required to get one point.\n3. If nums[
**Explanation**\n1. For any ```nums[i] ``` how many shifts are required to get one point ??\n2. ```Low ``` and ```high``` are min and max shifts required to get one point.\n3. If ```nums[i]``` is already satisfying the condition then ```low=0 and high =i-nums[i]``` shifts are required.\n4. If ```nums[i]``` is satisfying or not satisfying the condition then our ```low=i+1(to shift it to last index) and high=i+len(nums)-nums[i]```\n5. Use line sweep to calculate max points after ```i``` shifts\n\n**TC:- O(n),Sc:-O(n)**\n\n```\nclass Solution {\npublic:\n    int bestRotation(vector<int>& nums) {\n        int sz=nums.size();\n        vector<int>pointsForIShifts(2*sz+1,0);\n        for(int i=0;i<sz;i++){\n            int l=0,h=0;\n            if(nums[i]<=i){\n                l=0;h=i-nums[i];\n                pointsForIShifts[l]+=1;pointsForIShifts[h+1]-=1;\n            }\n            l=i+1;h=i+sz-nums[i];\n            pointsForIShifts[l]+=1;pointsForIShifts[h+1]-=1;            \n        }\n        int maxP=pointsForIShifts[0],k=0;\n        for(int i=1;i<pointsForIShifts.size();i++){\n            pointsForIShifts[i]+=pointsForIShifts[i-1];\n            if(pointsForIShifts[i]>maxP){\n                maxP=pointsForIShifts[i];\n                k=i;\n            }\n        }\n        return k;\n    }\n};\n```\nDo **UPVOTE** if it helps :)
['C']