【Hex】Python - Difference Array
Solution\nA number num, the final and coordinate difference is less than or equal to 0, there is only one range, that is, the coordinates are in [num, n-1]\n, a
## Solution\nA number num, the final and coordinate difference is less than or equal to 0, there is only one range, that is, the coordinates are in `[num, n-1]`\n, and the time difference between `[0, num-1]` will obviously be greater than 0.\n\n````\nTake nums=[2,3,1,4,0] as an example to illustrate\n        i=0,nums[i]=2 To score, it needs to be adjusted to the 2~4 position, and it needs to be adjusted 1~3 steps\n        i=1,nums[i]=3 To score, it needs to be adjusted to the 3~4 position, and it needs to be adjusted for 2~3 steps\n        i=2,nums[i]=1 To score, you need to adjust to 1~4 position, you need to adjust 0~1 and 3~4 steps (3~1)\n        i=3,nums[i]=4 To score, it needs to be adjusted to the 4~4 position, and it needs to be adjusted 4~4 steps\n        i=4,nums[i]=0 To score, you need to adjust to 0~4 position, you need to adjust 0~4 steps\n        To sum up, for each nums[i], the number of arguments k wants to make the upper and lower bounds of the number score: [(i+1)%n,(i+n-nums[i])%n]\n        For i=2, nums[i]=1 is a special case, the upper and lower bounds 3 and 1 can also be calculated by the formula, and 0 and 4 need to be supplemented by themselves\n        Finally, we count the range coverage of k corresponding to each nums[i], k represents the score in a certain coverage times, and the minimum value of k corresponding to the highest score (the most coverage times) is the answer\n\n````\n\n```python\n#O(n) time | O(n) space\nclass Solution:\n    def bestRotation(self, nums: List[int]) -> int:\n        diff = [0] * len(nums)\n        for i, v in enumerate(nums):\n            low = (i+1)% len(nums)\n            high = (i - v + len(nums)+1)%len(nums)\n            diff[low] +=1 # start \n            diff[high] -=1 # end+1 \n            if low >= high:\n                diff[0] +=1\n        \n        current = 0\n        maxi = 0\n        idx = 0\n        for i, v in enumerate(diff):\n            current += v\n            if current>maxi:\n                maxi = current\n                idx = i\n        return idx\n```
['Array', 'Python3']