Python with explanation in comments
\nclass Solution:\n    def bestRotation(self, nums: List[int]) -> int:\n        n = len(nums)\n        # https://walkccc.me/LeetCode/problems/0798/\n        # r
```\nclass Solution:\n    def bestRotation(self, nums: List[int]) -> int:\n        n = len(nums)\n        # https://walkccc.me/LeetCode/problems/0798/\n        # rotate[i] will represent\n        # how many scores achieved after rotating left the array i times\n        rotate = [0]*n\n        \n        # we have been told that any entries that are less than or equal to their\n        # index are worth one point. hence if +1 if v <= i, where v = nums[i]\n        # hence, +1 if i >= v. remember this. [1]\n        \n        # if we rotate left by 1 then, new index of element at index i will become i - 1\n        # hence, we know that rotating left \n        # an element at index i by v, makes the new index of that \n        # element, newIndex = i - (i-v) = v, this earns us a 1 point since newIndx = v\n        # now, if we rotate newindex by 1 = (i-v+1), then newIndex become \n        # v-1 which is less then v, which will not earn any point. \n        # in other words, lose point.\n        # hence, as per [1] remembered above, by rotating left (i-v+1+n) % n times, \n        # we lose points. +n and then % n so that, we can ensure it remains positive\n        for i in range(n):\n            rotate[(i - nums[i] + 1 + n) % n] -= 1\n        \n        # if an element is at index 0 and we rotate left, \n        # it going to earn us 1 point for sure. this is because\n        # each element is guaranteed to be nums[i] < nums.length as told in problem \n        # description. hence, all numbers are guaranteed to be less or equal to n -1 \n        # so we know v <= n-1 for sure all times, hence\n        # all rotations will earn at least 1 point for us.\n        \n        # apart from this, since moving left by 1, makes new_index = i-1\n        # hence, whatever score rotate[i-1] has, rotate i will have and +1 for the reason\n        # just mentiobed abive\n        for i in range(1,n):\n            rotate[i] += rotate[i-1] + 1\n        \n        maxscore = -11111111\n        k = 0\n        for i, score in enumerate(rotate):\n            if score > maxscore:\n                k = i\n                maxscore = score\n                \n        return k\n``` \n
[]