You are viewing a single comment's thread. Return to all comments →
Faster O(1) time and can be done in O(1) space also ... but i ve used more variables for better understanding....
include using namespace std;
int main(){
int noOfCases, len, rots, newPosi, temp, i, ans, newLen; cin >> len >> rots >> noOfCases; int arr[len]; for(i=0; i<len; i++){ cin >> arr[i]; } while(noOfCases != 0){ cin >> newPosi; temp = rots/len; newLen = len*(temp+1); ans = (newPosi + newLen - rots)%len; cout << arr[ans] << endl; noOfCases --; }
}
Seems like cookies are disabled on this browser, please enable them to open this website
Circular Array Rotation
You are viewing a single comment's thread. Return to all comments →
Faster O(1) time and can be done in O(1) space also ... but i ve used more variables for better understanding....
include using namespace std;
int main(){
}