Just doo it in O(n) time complexity


#1

vector Solution::rotateArray(vector &A, int B) {
vector arr;
for (int i = 0; i < A.size(); i++) {
if(B>=A.size())
{
B=B%(A.size());
}
vector arr;
for(int i=0;i<A.size();i++)
{
if(i<A.size()-B)
{
arr.push_back(A[B+i]);
}
else
{
arr.push_back(A[i-(A.size()-B)]);
}
}
return arr;
}

}