Rotate Array
easy⏱ 15 mintypescriptchallengesproblem-solving-basic-
Caso de ejemplo — tu programa lee de stdin e imprime en stdout.
Given an array, rotate it to the right by k steps.
Example: [1,2,3,4,5,6,7], k=3 → Rotate right 3 times → [5,6,7,1,2,3,4]
Optimized approach: Use the reversal algorithm - reverse entire array, reverse first k, reverse rest.
Formato de entrada
Line 1: n k (array size and rotation count). Line 2: n space-separated integers.
Formato de salida
The rotated array as space-separated integers.
Restricciones
1 ≤ n ≤ 10⁵, 0 ≤ k ≤ 10⁵