⚡️JS | TS⚡️ easy explained solution | Two Pointers | O(n) O(1)🔥
Approach\n Describe your approach to solving the problem. \nTwo pointers\n\n# Complexity\n- Time complexity:\n Add your time complexity here, e.g. O(n) \nO(n)\n
# Approach\n<!-- Describe your approach to solving the problem. -->\nTwo pointers\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1)\n\n# Code\n```\n/**\n Do not return anything, modify nums in-place instead.\n */\nfunction rotate(nums: number[], k: number): void {\n  k = k % nums.length;\n  let l = 0;\n  let r = nums.length - 1;\n  // reverse full given array\n  // from [1,2,3,4,5,6,7] to [7,6,5,4,3,2,1]\n  nums = reverseArr(nums, l, r);\n\n  // reverse part from 0 to k - 1;\n  // from [7,6,5,4,3,2,1] to [5,6,7,4,3,2,1]\n  l = 0;\n  r = k - 1;\n  nums = reverseArr(nums, l, r);\n\n  // reverse part from k to the end;\n  // from [5,6,7,4,3,2,1] to [5,6,7,1,2,3,4]\n  l = k;\n  r = nums.length - 1;\n  nums = reverseArr(nums, l, r);\n};\n\nfunction reverseArr(nums: number[], l: number, r: number): number[] {\n    while(l < r) {\n    let temp = nums[l];\n    nums[l] = nums[r];\n    nums[r] = temp;\n    l++;\n    r--;\n  }\n\n  return nums;\n}\n\n```\nPlease do not forget to upvote the solution in case it is helpfull for you \uD83D\uDD25
['Two Pointers', 'TypeScript', 'JavaScript']