S
All challenges
Practice
Home
Blog
Practice
Examples
Feedback
Rotate Array by K Steps
00:00
Start
00:00
Sign in
Problem
Hints
3
Solution
History
Easy
Array
Two Pointers
Math
Microsoft
Amazon
Rotate integer array to the right by k steps. k may be larger than array length.
Examples
Example 1
Input →
[1,2,3,4,5,6,7], k=3
Output →
[5,6,7,1,2,3,4]
Example 2
Input →
[-1,-100,3,99], k=2
Output →
[3,99,-1,-100]
Example 3
Input →
[1,2], k=3
Output →
[2,1]
Note:
k%2=1
JavaScript
Python
Java (Coming soon)
C (Coming soon)
C++ (Coming soon)
Reset
Run
Submit
Cases
Results