You are viewing a single comment's thread. Return to all comments →
vector rotateLeft(int d, vector arr) { int n = arr.size(); if(d>n){ d = d%n; } reverse(arr.begin(),arr.begin()+d); reverse(arr.begin()+d,arr.end()); reverse(arr.begin(),arr.end()); return arr; }
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 →
vector rotateLeft(int d, vector arr) { int n = arr.size(); if(d>n){ d = d%n; } reverse(arr.begin(),arr.begin()+d); reverse(arr.begin()+d,arr.end()); reverse(arr.begin(),arr.end()); return arr; }