C++ Cyclic Rotation
#include <vector>
std::vector<int> cyclicRotation(std::vector<int> a, int k)
{
if (!a.empty()) {
for (int i = 0; i < k; ++i) {
int back = a.back();
a.pop_back();
a.insert(a.begin(), back);
}
}
return a;
}
This rotates the array to the right by K steps and keeps the wrap-around values in the correct order.