4 solutions in python (From easy to hard)
A good start ito think a wayt out is brute force \n\n1. Approach #1 \n\n   varaible previous to store the number being replaced.\n\n   python\n   class Solution
A good start ito think a wayt out is brute force \n\n1. Approach #1 \n\n   varaible `previous` to store the number being replaced.\n\n   ```python\n   class Solution1:\n       def rotate(self, nums, k):\n           """\n           :type nums: List[int]\n           :type k: int\n           :rtype: None Do not return anything, modify nums in-place instead.\n           """\n           for _ in range(k):\n               previous = nums[-1] #initiate a first previous \n               for i in range(len(nums)):\n                   temp = nums[i] #hodl nums[i]\n                   nums[i] = previous #overwrite the current index \n                   previous = temp #swap the value \n           logging.debug(f"nums: {nums}")\n   ```\n\n   **Complexity Analysis**\n\n   - Time complexity : O( *n*\u2217*k*). All the numbers are shifted by one step(O (n)*O*(*n*)) k times(O (k)*O* ( *k* ) ).\n   - Space complexity : O(1). No extra space is used.\n\n2. Approch #2 Using Extra Array\n\n   We use an extra array in which we place every element of the array at its correct position i.e. the number at index i*i* in the original array is placed at the index (i+k)%(length of array)(*i*+*k*). Then, we copy the new array to the original one.\n\n   ```python\n   class Solution2:\n       def rotate(self, nums, k):\n           """\n           :type nums: List[int]\n           :type k: int\n           :rtype: None Do not return anything, modify nums in-place instead.\n           """\n           a = [0] * len(nums)\n           for i in range(len(nums)):\n               a[(i+k)%len(nums)] = nums[i] #recycle\n   \n           for i in range(len(nums)):\n               nums[i] = a[i]\n   ```\n\n   **Complexity Analysis**\n\n   - Time complexity : O(n). One pass is used to put the numbers in the new array. And another pass to copy the new array to the original one.\n   - Space complexity :O*(*n). Another array of the same size is used.\n\n\n\n3. Approach #3 Using Cyclic Replacements\n\n   ![solution 3](https://leetcode.com/media/original_images/189_Rotate_Array.png)\n\n   ```python\n   class Solution3:\n       def rotate(self, nums, k):\n           """\n           :type nums: List[int]\n           :type k: int\n           :rtype: None Do not return anything, modify nums in-place instead.\n           """\n           k = k % len(nums)\n           count = 0\n           start = 0\n           while count < len(nums):\n               current = start \n               prev = nums[start] #store the value in the position\n               \n               while True:\n                   next = (current + k) % len(nums) #\n                   temp = nums[next] #store it temporaly \n                   nums[next] = prev #overide the next \n                   prev = temp #reset prev\n                   current = next #reset current\n                   count += 1\n   \n                   if start == current:\n                       break \n               \n               start += 1\n   ```\n\n   **Complexity Analysis**\n\n   - Time complexity : O(n). Only one pass is used.\n   - Space complexity : O(1). Constant extra space is used.\n\n\n\n\n\n4. #### Approach #4 Using Reverse \n\n   **Algorithm**\n\n   This approach is based on the fact that when we rotate the array k times, k%n*k* elements from the back end of the array come to the front and the rest of the elements from the front shift backwards.\n\n   In this approach, we firstly reverse all the elements of the array. Then, reversing the first k elements followed by reversing the rest n-k*n*\u2212*k*elements gives us the required result.\n\n   Let n=7*n*=7 and k=3*k*=3.\n\n   ```python\n   Original List                   : 1 2 3 4 5 6 7\n   After reversing all numbers     : 7 6 5 4 3 2 1\n   After reversing first k numbers : 5 6 7 4 3 2 1\n   After revering last n-k numbers : 5 6 7 1 2 3 4 --> Result\n   ```\n\n   ```python\n   class Solution4:\n       def rotate(self, nums, k) -> None:\n           """\n           :type nums: List[int]\n           :type k: int\n           :rtype: None Do not return anything, modify nums in-place instead.\n           """\n           k %= len(nums)\n           self.reverse(nums,0,len(nums)-1)\n           self.reverse(nums,0, k-1)\n           self.reverse(nums,k, len(nums)-1)\n   \n       def reverse(self, nums, start, end) -> None:\n           """\n           :type nums: List[int]\n           :type start: int\n           :type end: int\n           :rtype: None\n           """\n           while start < end: #\n               temp = nums[start]\n               nums[start] = nums[end]\n               nums[end] = temp \n               start += 1\n               end -= 1\n   ```\n\n   \n\n   **Complexity Analysis**\n\n   - Time complexity : O(n) .n*n*elements are reversed a total of three times.\n   - Space complexity : O(1). No extra space is used.\n
['Python']