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
|
3077 Discussions
|
Please Login in order to post a comment
Here is my c++ solution, you can watch the explanation here : https://youtu.be/MaT-4dnozJI
Solution 1 O(n + m) :
Solution 2 O(m) :
JS/Javascript solutiuon:-
C++ Solution
vector circularArrayRotation(vector a, int k, vector queries) { vector res; for(auto& q : queries) { int index = (q + a.size() - k%a.size()); if(index >= a.size()) index = index % a.size(); res.push_back(a[index]); } return res; }
My solution