C# Cyclic Rotation
static int[] CyclicRotation(int[] a, int k)
{
if (a.Length == 0)
{
return a;
}
var list = new List<int>(a);
for (int i = 0; i < k; i++)
{
var last = list[^1];
list.RemoveAt(list.Count - 1);
list.Insert(0, last);
}
return list.ToArray();
}
This rotates the array to the right by K steps and keeps the wrap-around values in the correct order.