I’m working on understanding the below solution of rotating an array of integers in Python:
- Does the range function start counting at 0?
- Do we assume array indexing starts goes 0,1,2… or 1,2,3…?
- Why do we need to transfer the rotated values from the new array a to the old array nums (last line)?
class Solution: def rotate(self, nums: List[int], k: int) -> None: n = len(nums) a =  * n for i in range(n): a[(i + k) % n] = nums[i] nums[:] = a
It is supposed to work as follows: Input: nums = [1,2,3,4,5,6,7], k = 3 Output: [5,6,7,1,2,3,4]