Rotate Array Left
Hard
arrays
algorithms
Description
Rotate the elements of an array to the left by `k` steps. The rotation should be done in-place or return a new rotated array.
Examples
Example:
Input: array: [1, 2, 3, 4, 5], k: 2
Output: [3, 4, 5, 1, 2]
Explanation: Step 1: [2, 3, 4, 5, 1]. Step 2: [3, 4, 5, 1, 2].
Constraints
- Input is a list of integers.
- k is a non-negative integer.
- If k > array length, k should wrap (k % len(array)).
Loading...
Test Case 1
Input: [1,2,3,4,5],2
Output: [3,4,5,1,2]
Test Case 2
Input: [-1,-100,3,99],1
Output: [-100,3,99,-1]
Test Case 3
Input: [1,2],3
Output: [2,1]
