<jupyter_start><jupyter_text>Given an array, rotate the array to the right by k steps, where k is non-negative.Example 1:    Input: [1,2,3,4,5,6,7] and k = 3    Output: [5,6,7,1,2,3,4]    Explanation:    rotate 1 steps to the right: [7,1,2,3,4,5,6]    rotate 2 steps to the right: [6,7,1,2,3,4,5]    rotate 3 steps to the right: [5,6,7,1,2,3,4]Example 2:    Input: [-1,-100,3,99] and k = 2    Output: [3,99,-1,-100]    Explanation:     rotate 1 steps to the right: [99,-1,-100,3]    rotate 2 steps to the right: [3,99,-1,-100]Note:- Try to come up as many solutions as you can, there are at least 3 different ways to solve this problem.- Could you do it in-place with O(1) extra space?<jupyter_code>class Solution:
    def rotate(self, nums, k):
        '''
        nums: List[int]
        k: int
        rtype: None
        '''
        
        """
        Do not return anything, modify nums in-place instead.
        """
        newarr = [0] * len(nums)
        for i in range(len(nums)):
            newarr[(i+k)%len(nums)] = nums[i]
            
        for i in range(len(nums)):
            nums[i] = newarr[i]
        return nums
        
# test
nums = [1,2,3,4,5,6,7]
k = 3
Solution().rotate(nums,k)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14620355411954766, 'fraction_numerical': 0.06704361873990307, 'mean_word_length': 2.441666666666667, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '440755', 'license': 'MIT', 'n_tokens_mistral': 497, 'n_tokens_neox': 461, 'n_words': 141, 'path': 'DSA/arrays/rotate.ipynb', 'repo_name': 'lance-lh/Data-Structures-and-Algorithms', 'size': '1238'}