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.
#include<iostream>#include<vector>#include<algorithm>#include<iterator>intmain(){intn;std::cin>>n;// array sizeintk;std::cin>>k;//no of rotationsintq;std::cin>>q;std::vector<int>vec;vec.reserve(n);std::copy_n(std::istream_iterator<int>(std::cin),n,back_inserter(vec));k%=n;k=n-k;std::rotate(vec.begin(),vec.begin()+k,vec.end());while(q--){intindex;std::cin>>index;std::cout<<vec[index]<<std::endl;}return0;}
Cookie support is required to access HackerRank
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 →
simpler one: