798. Smallest Rotation with Highest Score.cpp
Code\n\nclass Solution {\npublic:\n    int bestRotation(vector<int>& nums) {        \n        vector<pair<int,int>>goodIndices;\n        map<int,int>mp;        
**Code**\n```\nclass Solution {\npublic:\n    int bestRotation(vector<int>& nums) {        \n        vector<pair<int,int>>goodIndices;\n        map<int,int>mp;        \n        for(int i=0;i<nums.size();i++)\n        if(nums[i]<=i)\n        goodIndices.push_back({0,i-nums[i]}) , goodIndices.push_back({i+1,nums.size()-1});\n        else\n        goodIndices.push_back({i+1 , i+ (nums.size()-nums[i])});        \n        for(auto i:goodIndices)\n        mp[i.first]++ , mp[i.second+1]--;        \n        int tempsum = 0 , rotations=0 , sum=0;\n        for(int i=0;i<nums.size();i++)\n        tempsum+=mp[i] , rotations=tempsum>sum?i:rotations  , sum=max(tempsum,sum);      \n        return rotations;\n    }\n};\n```
['C']