Rotate Array


I wrote something to help understanding the third Cyclic Replacements approach:interpretation/proof

Consider the following enhanced version of Approach #3 Using Cyclic Replacements in C++.
It first converts the problem into the equivalent rotation to the left of n  (k % n) positions. Then rotate each cycle directly in the vector, storing in the temp variable the first element only.
class Solution { public: void rotate(vector<int>& nums, int k) { int n = nums.size(); k = n  (k % n); int count = 0; for (int begin = 0; count < n; begin++) { int temp = nums[begin]; int curr = begin; for (int next = (curr + k) % n; next != begin; next = (curr + k) % n) { nums[curr] = nums[next]; curr = next; count++; } nums[curr] = temp; count++; } } };

This solution doesn't work for the following condition
Input: array: [1,2,3,4,5] and k = 4
Output: [5,1,2,3,4]
Could anyone tell me what is the issue with this code?def rotateArray(nums, k): k = k%len(nums) end = len(nums)  1 if k is None or k<= 0: return reverse(nums, 0, end  k) reverse(nums, end  k + 1, end) return reverse(nums, 0, end) def reverse(nums, start, end): while start < end: nums[start], nums[end] = nums[end],nums[start] start += 1 end = 1 return nums print rotateArray([1,2,3,4,5], 4)

//Example for Rotate Array in C [Accepted] void rotate(int* nums, int numsSize, int k) { int *nArry = malloc(numsSize*sizeof(int)); if(numsSize<k) k %= numsSize; for(int i=0; i<numsSize; i++) if(i<(numsSizek)) nArry[i+k] = nums[i]; else nArry[i(numsSizek)] = nums[i]; for(int i=0; i<numsSize; i++) nums[i]=nArry[i]; }