#48 - Rotate Array by K times
You are given an array of integers and an integer k. Your task is to implement a function to rotate the array to the left or right by k positions.
Example 1
Input
nums = [1, 2, 3, 4, 5]
k = 2
direction = "left"Output
[3, 4, 5, 1, 2]Example 2
Input
nums = [1, 2, 3, 4, 5]
k = 2
direction = "right"Output
Last updated