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

&nbsp;
Example 1:

Input: nums = [1,2,3,4,5,6,7], 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: nums = [-1,-100,3,99], 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]


&nbsp;
Constraints:


	1 &lt;= nums.length &lt;= 105
	-231 &lt;= nums[i] &lt;= 231 - 1
	0 &lt;= k &lt;= 105


&nbsp;
Follow up:


	Try to come up with as many solutions as you can. There are at least three different ways to solve this problem.
	Could you do it in-place with O(1) extra space?


class Solution:
    def reverse(self,arr,left,right):
        while left < right:
            arr[left],arr[right] = arr[right], arr[left]
            left, right = left + 1, right - 1
        return arr
    def rotate(self, nums: List[int], k: int) -> None:
        length = len(nums)
        k = k % length
        l, r = 0, length - 1
        nums = self.reverse(nums,l,r)
        l, r = 0, k - 1
        nums = self.reverse(nums,l,r)
        l, r = k, length - 1
        nums = self.reverse(nums,l,r)
        return nums
class Solution {
    public void rotate(int[] nums, int k) {
        reverse(nums , 0 , nums.length-1);
        reverse(nums , 0 , k-1);
        reverse(nums , k , nums.length -1);
    }
    
    public static void reverse(int[] arr , int start , int end){
        while(start<end){
            int temp = arr[start];
            arr[start] = arr[end];
            arr[end] = temp;
            start++;
            end--;
        }
    }
}
class Solution {
public:
    void rotate(vector<int>& nums, int k) {

        vector<int> temp(nums.size());
        for(int i = 0; i < nums.size() ;i++){

            temp[(i+k)%nums.size()] = nums[i];

        }

        nums = temp;
    }
};
/**
 * @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 %= len;
    const t = nums.splice(len - k, k);
    nums.unshift(...t);
};
Rotate Array