[Python3] difference array
\n\nclass Solution:\n    def bestRotation(self, nums: List[int]) -> int:\n        diff = [0]*(len(nums) + 1)\n        for i, x in enumerate(nums): \n           
\n```\nclass Solution:\n    def bestRotation(self, nums: List[int]) -> int:\n        diff = [0]*(len(nums) + 1)\n        for i, x in enumerate(nums): \n            diff[i+1] += 1\n            if x <= i: diff[0] += 1\n            diff[(i-x)%len(nums) + 1] -= 1\n        \n        ans = prefix = 0 \n        mx = -inf \n        for i, x in enumerate(diff): \n            prefix += x\n            if prefix > mx: mx, ans = prefix, i\n        return ans \n```\n\n```\nclass Solution:\n    def bestRotation(self, nums: List[int]) -> int:\n        diff = [1] * len(nums)\n        for i, x in enumerate(nums): \n            diff[(i-x+1) % len(nums)] -= 1\n        prefix = list(accumulate(diff))\n        return prefix.index(max(prefix))\n```
['Python3']