Given an integer vector and a value k,rotate the array k times clockwise.
Eg- {1,2,3,4,5} on rotating twice becomes {4,5,1,2,3}
Here’s what I tried:
vector<int> kRotate(vector<int> a, int k){
int n = a.size();
vector <int> arr_new(n,0);
for [int i = 0; i<n; i++]{
arr_new.at((i+k)%(n))= a[i];
};
return arr_new;
}
However this returns a segmentation error on line 4.Can someone help?
New contributor
Someon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.