C++, run example + observation + convert to diff array of k
\n/*\nsee below example:\n\n   0 1 2 3 4 5   index\n   x x x x 2 x   value\n   0 0 1 1 1 1   scroe\n\n   0 1 2 3 4 5\n   x 4 x x x x\n   0 0 0 0 1 1\n\n   0 1 2
```\n/*\nsee below example:\n\n   0 1 2 3 4 5   index\n   x x x x 2 x   value\n   0 0 1 1 1 1   scroe\n\n   0 1 2 3 4 5\n   x 4 x x x x\n   0 0 0 0 1 1\n\n   0 1 2 3 4 5    k\n   1 1 1 0 0 1    score\n   \n   0 1 2 3 4 5\n   0 0 1 1 0 0\n\n\n*/\n\n\nconst int N = 1e5 + 10;\n\nclass Solution {\n    int diff[N] = {};\npublic:\n    int bestRotation(vector<int>& arr) {\n        int n = arr.size();\n        for (int i = 0; i < n; ++ i)\n        {\n            int dist = i - arr[i];\n            if (i < arr[i])\n            {\n                diff[i + 1] += 1;\n                diff[(dist + n) % n + 1] -= 1;                \n            }\n            else \n            {\n                diff[0] += 1;\n                diff[dist + 1] -= 1;\n                \n                diff[(-(n - 1 - i) + n) % n] += 1;\n                diff[0] -= 1;\n            }\n        }\n        for (int i = 1; i < N; ++ i) diff[i] += diff[i - 1];\n        return max_element(diff, diff + n) - diff;\n    }\n};\n```
[]