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.

  1. Normalize the rotation: k = k % nums.length (since rotating a length of 5 by 5 brings you back to the start).
  2. To simulate the rotation without complex array methods:
    • Print the last k elements of the array first (starting from length - k).
    • Then, print the first length - k elements (starting from 0).
  3. Each number should appear on a new line.

01EXAMPLE 1

Inputnums=[1, 2, 3], k=1
Output3 1 2

Explanation: 3 moves to the start.

Constraints

  • Do not use .slice() or .concat()—use manual loops.
ArraysAlgorithms
JavaScript
Loading...
1 Hidden

Input Arguments

nums[1,2,3]
k1

Expected Output

3
1
2

Click RUN to test your solution