(C++) 798. Smallest Rotation with Highest Score
\n\nclass Solution {\npublic:\n    int bestRotation(vector<int>& nums) {\n        int n = size(nums); \n\n        vector<int> diff(n, 1); \n        for (int i =
\n```\nclass Solution {\npublic:\n    int bestRotation(vector<int>& nums) {\n        int n = size(nums); \n\n        vector<int> diff(n, 1); \n        for (int i = 0; i < n; ++i) \n            diff[(i+n-nums[i]+1) % n]--; \n        \n        int ans = 0, prefix = 0, mx = INT_MIN; \n        for (int i = 0; i < n; ++i) {\n            prefix += diff[i]; \n            if (prefix > mx) {\n                mx = prefix; \n                ans = i; \n            }\n        }\n        return ans; \n    }\n};\n```
['C']