rotate an array of n elements to the right by k steps for example with n 7 and k 3 the array 1 2 3 4 5 6 7 is rotated to 5 6 7 1 2 3 4 note try to come up as many solutions as you can there are at least 3 different ways to solve this problem rotate the entire array k times tn onk type array listint type k int rtype void do not return anything modify array inplace instead reverse segments of the array followed by the entire array tn on type array listint type k int rtype void do not return anything modify nums inplace instead rotate the entire array k times t n o nk type array list int type k int rtype void do not return anything modify array in place instead unused variable is not a problem reverse segments of the array followed by the entire array t n o n type array list int type k int rtype void do not return anything modify nums in place instead
def rotate_v1(array, k):
    
    array = array[:]
    n = len(array)
    for i in range(k):      
        temp = array[n - 1]
        for j in range(n-1, 0, -1):
            array[j] = array[j - 1]
        array[0] = temp
    return array


def rotate_v2(array, k):
    
    array = array[:]

    def reverse(arr, a, b):
        while a < b:
            arr[a], arr[b] = arr[b], arr[a]
            a += 1
            b -= 1

    n = len(array)
    k = k % n
    reverse(array, 0, n - k - 1)
    reverse(array, n - k, n - 1)
    reverse(array, 0, n - 1)
    return array


def rotate_v3(array, k):
    if array is None:
        return None
    length = len(array)
    k = k % length
    return array[length - k:] + array[:length - k]