Write a function rotate_array(arr, k) that rotates an array to the right by k positions. Elements that go past the end wrap around to the beginning.
Example:
Input: arr = [1, 2, 3, 4, 5], k = 2
Output: [4, 5, 1, 2, 3]
Input: arr = [1, 2, 3], k = 1
Output: [3, 1, 2]
Constraints:
Test Cases
Test Case 1
Input:
[1, 2, 3, 4, 5], 2Expected:
[4, 5, 1, 2, 3]Test Case 2
Input:
[1, 2, 3], 1Expected:
[3, 1, 2]Test Case 3
Input:
[1, 2, 3, 4], 0Expected:
[1, 2, 3, 4]+ 2 hidden test cases