Rotate right by k08.04
Right-rotate by k sends a[i] to (i+k) % n. It is left-rotate by n-k.
Right by 1 wraps last to front. Right by k does that k times, or in one mapping.
Same skill, three traces. Read all three before you try it.
01k=1 - given
a = [4, 1, 9, 1],k = 1- walk
last
1to front- result
[1, 4, 1, 9]
02k=2 - given
a = [4, 1, 9, 1],k = 2- walk
9,1move to front- result
[9, 1, 4, 1]
03right k = left n-k - given
a = [4, 1, 9, 1],n = 4, right1= left3- walk
[1, 4, 1, 9]both ways- result
- same array
rotR(a, k).a is an array of integers. n is a.length. k is how many steps right.Move each
a[i] to (i + k) % n. Return the rotated array.On
[4, 1, 9, 1]: k=1 → [1, 4, 1, 9]. k=2 → [9, 1, 4, 1]. Check rotR(a, 1) equals rotL(a, 3).constraintsa has length ≥ 2. 0 ≤ k < n.
- Rotate Array0/3 skills ready · arrays · mediumopen
- Rotate Array0/3 skills ready · arrays · mediumopen
Every Check with Awel is frozen here. Open one to read the code or load it back into the editor.