Rotation Pulse
HardAcc. 82.7%
+40 XP 20
The Dimensional Shift (Rotation)
Data rotation is like turning a wheel: the items at the end of the line move to the very front. This "circular shift" is fundamental in cryptographic algorithms and cyclic buffers. While you could move them one by one, a more efficient way is to think about the "Cut Point" ($K$).
The Assignment
Your mission is to rotate the array sequence. Your function receives an array nums and a rotation count k.
- Normalize the rotation:
k = k % nums.length(since rotating a length of 5 by 5 brings you back to the start). - To simulate the rotation without complex array methods:
- Print the last
kelements of the array first (starting fromlength - k). - Then, print the first
length - kelements (starting from0).
- Print the last
- Each number should appear on a new line.
01EXAMPLE 1
Input
nums=[1, 2, 3], k=1Output
3
1
2Explanation: 3 moves to the start.
Constraints
- Do not use .slice() or .concat()—use manual loops.
ArraysAlgorithms
JavaScriptSystem handles I/O — write your function only
Loading...
1 Hidden
Input Arguments
nums[1,2,3]
k1
Expected Output
3 1 2
Click RUN to test your solution