You are viewing a single comment's thread. Return to all comments →
Simple C++ code having time complexity= O(n) and space complexity = O(n)
vector<int> rotateLeft(int d, vector<int> arr) { vector<int> result(arr.size()); for(int i=0;i<arr.size();i++){ int index; if (i-d<0) index=arr.size()-(abs(i-d)%arr.size()); else index=i-d; result[index]=arr[i]; } return result; }
Seems like cookies are disabled on this browser, please enable them to open this website
Left Rotation
You are viewing a single comment's thread. Return to all comments →
Simple C++ code having time complexity= O(n) and space complexity = O(n)