# Leet Code 189: Rotate Array

### Problem statement:

Given an array, rotate the array to the right by k steps, where k is non-negative.

### Constraints:

• 1 <= nums.length <= 105
• -231 <= nums[i] <= 231 - 1
• 0 <= k <= 105

### Soultion

```.css-1r5hp7i{position:absolute;top:0;right:0;z-index:1;border-radius:0 5px 0 5px;padding:0.25rem 0.6rem;border:none;cursor:pointer;background:#44475a;color:rgb(248, 248, 242);-webkit-transition:all 200ms ease;transition:all 200ms ease;font-size:12px;}.css-1r5hp7i:disabled{cursor:not-allowed;}.css-1r5hp7i:not(:disabled):hover,.css-1r5hp7i:not(:disabled):focus{background:#8257E6;}```/** * @param {number[]} nums * @param {number} k * @return {void} Do not return anything, modify nums in-place instead. */var rotate = function(nums, k) {        const len = nums.length;    k = k % len;    nums = reverse(nums, 0, len-1);    nums = reverse(nums, 0, k-1);    nums = reverse(nums, k, len-1);};
function reverse(arr = [], l, r) {    while(l<r) {        let temp = arr[l];        arr[l] = arr[r];        arr[r] = temp;        l++;        r--;    }    return arr;}``````