We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Circular Array Rotation
Circular Array Rotation
Sort by
recency
|
3109 Discussions
|
Please Login in order to post a comment
List res=new ArrayList<>(); int n=a.size(); k=k%n; for(int q:queries){ int newIndex=(q-k+n)%n; res.add(a.get(newIndex)); } return res;
Test failed succesfully???
Test case 4 says success but it's marked red, as if it failed?
My python solution:
My C++ solution
vector circularArrayRotation(vector & arr, int k, vector queries) { vector res; // k % arr.size() enusre that we are not unnecessarily rotating back to original std::rotate(arr.rbegin(), arr.rbegin() + (k % arr.size()), arr.rend());
}