def rotate_v2(array, k):
array = array[:]<EOL>def reverse(arr, a, b):<EOL><INDENT>while a < b:<EOL><INDENT>arr[a], arr[b] = arr[b], arr[a]<EOL>a += <NUM_LIT:1><EOL>b -= <NUM_LIT:1><EOL><DEDENT><DEDENT>n = len(array)<EOL>k = k % n<EOL>reverse(array, <NUM_LIT:0>, n - k - <NUM_LIT:1>)<EOL>reverse(array, n - k, n - <NUM_LIT:1>)<EOL>reverse(array, <NUM_LIT:0>, n - <NUM_LIT:1>)<EOL>return array<EOL>
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.