TypeScript Cyclic Rotation
function cyclicRotation(a: number[], k: number): number[] {
const result = [...a];
if (result.length > 0) {
for (let i = 0; i < k; i++) {
const popped = result.pop() as number;
result.unshift(popped);
}
}
return result;
}
This rotates the array to the right by K steps and keeps the wrap-around values in the correct order.