Rotate Array
Medium · two pointers
A conveyor belt carries nums, a list of parcels in a fixed order. When the belt turns by one step, the last parcel falls off the end and is placed back at the front.
Turn the belt k steps and return the new list of parcels.
Examples
Example 1
Input: nums = [10, 20, 30, 40, 50], k = 2
Output: [40, 50, 10, 20, 30]
After one step the belt reads [50, 10, 20, 30, 40]; after the second it reads [40, 50, 10, 20, 30].
Example 2
Input: nums = [5, -3, 8, 0], k = 3
Output: [-3, 8, 0, 5]
Example 3
Input: nums = [6, 1], k = 0
Output: [6, 1]
Constraints
- 1 <= len(nums) <= 10^5
- -10^9 <= nums[i] <= 10^9
- 0 <= k < len(nums)