← All problemsExample 1 Example 2
Problem
Rotate Array
Medium- arrays
Shift every element of nums k places to the right. An element that falls off the end comes around to the front. Return the rotated array.
- Input
nums = [10, 20, 30, 40, 50], k = 2- Output
[40, 50, 10, 20, 30]- Explanation
the last two elements, 40 and 50, wrap around to the front.
- Input
nums = [8, 9], k = 5- Output
[9, 8]- Explanation
kcan be larger than the array. Moving 5 places in an array of 2 gives the same result as moving 1 place.
Constraints:
1 <= nums.length <= 10^50 <= k <= 10^9, andkmay be larger thannums.length-10^9 <= nums[i] <= 10^9
Tab indents. Press Esc, then Tab to leave the editor.
Ctrl or ⌘ + Enter runs the tests.
Run your code to see every test here. Nothing is submitted or recorded.