simplest way using insert() and pop()
Intuition\nTo rotate the array nums to the right by k steps, we can follow these steps:\n\n1. If k is greater than the length of nums, reduce k by taking its mo
# Intuition\nTo rotate the array nums to the right by k steps, we can follow these steps:\n\n1. If k is greater than the length of nums, reduce k by taking its modulo with the length of nums. This ensures that k falls within the range of valid rotations.\n2. Perform the rotation in-place by repeatedly popping the last element of the array and inserting it at the beginning for k times.\n# Approach\n\n1.\tCheck if k is greater than the length of nums. If so, reduce k by taking its modulo with the length of nums.\n2.\tPerform the rotation by iterating k times using a for loop:\n\u2022\tRemove the last element of nums using pop() and store it in a variable a.\n\u2022\tInsert the value a at the beginning of nums using insert().\n\n# Complexity\n- Time complexity: O(n^2)\nThe time complexity is proportional to the value of k since we need to rotate the array k times.\n\n- Space complexity: O(1)\nThe space complexity is constant as we are modifying the input array in-place and not using any additional data structures.\n# Code\n```\nclass Solution:\n    def rotate(self, nums: List[int], k: int) -> None:\n        for i in range(k):\n            a=nums.pop()\n            nums.insert(0,a)\n```\n\n##### reach me to discuss any problems - https://www.linkedin.com/in/naveen-kumar-g-500469210/\n![image.png](https://assets.leetcode.com/users/images/8d8328c3-f05f-4acb-9e6d-87c7a1abd695_1687413526.140085.png)\n
['Python3']