[c++] compute intervals
\nclass Solution {\npublic:\n    int bestRotation(vector<int>& nums) {\n        int n = nums.size();\n        vector<int> dp(n, 0);\n        for (int i = 0; i <
```\nclass Solution {\npublic:\n    int bestRotation(vector<int>& nums) {\n        int n = nums.size();\n        vector<int> dp(n, 0);\n        for (int i = 0; i < n; i++)\n        {\n            int l = nums[i];\n            int r = n - 1;\n            if (l > r) continue;\n            if (i < l) {\n                int a = i + 1;\n                int b = (a + r - l + 1);\n                dp[a]++;\n                if (b < n)\n                dp[b]--;\n            } else if (i <= r){\n                int a = 0;\n                int b = i - l + 1;\n                dp[a]++;\n                if (b < n)\n                dp[b]--;\n                \n                a = i + 1;\n                if (a < n)\n                dp[a]++;\n            } else if (i > r) {\n                int a = i - r;\n                int b = i - l + 1;\n                dp[a]++;\n                if (b < n)\n                dp[b]--;\n            }\n        }\n        int m = -1;\n        int ans = -1;\n        int cur = 0;\n        for (int i = 0; i < n; i++)\n        {\n            cur += dp[i];\n            if (cur > m) {\n                m = cur;\n                ans = i;\n            }\n        }\n        return ans;\n    }\n};\n```
[]