Why we compute bad intervals instead of good ones? C++ straightforward solution
Same idea, but more straightforward\n\n\n    //O(N), O(N)\n    int bestRotation(vector<int> A) {\n        int len = A.size();\n        vector<int> goods(len + 1
Same idea, but more straightforward\n```\n\n    //O(N), O(N)\n    int bestRotation(vector<int> A) {\n        int len = A.size();\n        vector<int> goods(len + 1);\n        for (int i = 0; i < len; ++i)\n        {\n            if (A[i] <= i)\n            {\n                // [0, i - A[i]] good, [i + 1, len] good\n                goods[0]++;\n                goods[i - A[i] + 1]--;\n                goods[i + 1]++;\n                goods[len]--;\n            }\n            else\n            {\n                // [i + 1, len + i - A[i] + 1] good\n                goods[i + 1]++;\n                goods[len + i - A[i] + 1]--;\n            }\n        }\n\n        int score = -1;\n        int cur = 0;\n        int res = 0;\n        for (int i = 0; i < len; ++i)\n        {\n            cur += goods[i];\n            if (cur > score)\n            {\n                score = cur;\n                res = i;\n            }\n        }\n\n        return res;\n    }\n```
[]