Rotate Array
Given an integer array nums, rotate the array to the right by k steps, where k is non-negative. Do it in-place with O(1) extra space.

30:00

Rotate Array
medium
Topics
Companies

Given an integer array nums, rotate the array to the right by k steps, where k is non-negative. Do it in-place with O(1) extra space.

Example 1:
Input: {"nums":[1,2,3,4,5,6,7],"k":3}
Output: [5,6,7,1,2,3,4]
Constraints:
  • 1nums.length1051 \leq \text{nums.length} \leq 10^5

  • 231nums[i]2311-2^{31} \leq \text{nums}[i] \leq 2^{31} - 1

  • 0k1050 \leq k \leq 10^5

Input
arr ={"nums":[1,2,3,4,5,6,7],"k":3}

Rotate array to the right by 3 steps

k = 3

normalized k = 3

Array
1
0
2
1
3
2
4
3
5
4
6
5
7
6
Currently Reversing
Variables
No variables to display
DepthFunction Call
Stack empty
0/5