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.
This is my solution in C++, pretty straightforward
intmain(){/* Enter your code here. Read input from STDIN. Print output to STDOUT */intsize_of_vector;intnum_of_rotations;intinput;cin>>size_of_vector>>num_of_rotations;vector<int>v1;for(inti=0;i<size_of_vector;++i){cin>>input;v1.push_back(input);}/*pushes back the first element in vector and deletes the first element(which was added to back) which creates a shift */for(inti=0;i<num_of_rotations;++i){inttemp=v1.at(0);v1.push_back(temp);v1.erase(v1.begin());}for(inti=0;i<size_of_vector;++i){std::cout<<v1.at(i)<<" ";}return0;}
Cookie support is required to access HackerRank
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 →
This is my solution in C++, pretty straightforward