HackerRank, Cracking the Coding Interview: Arrays - Left Rotation I just wanted to get some constructive feedback on my solution for this problem taken from the HackerRank Cracking the Coding Interview series.

CTCI Arrays Left Rotation Problem Statement

#include &lt;map&gt;
#include &lt;set&gt;
#include &lt;list&gt;
#include &lt;cmath&gt;
#include &lt;ctime&gt;
#include &lt;deque&gt;
#include &lt;queue&gt;
#include &lt;stack&gt;
#include &lt;string&gt;
#include &lt;bitset&gt;
#include &lt;cstdio&gt;
#include &lt;limits&gt;
#include &lt;vector&gt;
#include &lt;climits&gt;
#include &lt;cstring&gt;
#include &lt;cstdlib&gt;
#include &lt;fstream&gt;
#include &lt;numeric&gt;
#include &lt;sstream&gt;
#include &lt;iostream&gt;
#include &lt;algorithm&gt;
#include &lt;unordered_map&gt;

using namespace std;

vector&lt;int&gt; array_left_rotation(vector&lt;int&gt; a, int n, int k) {
    vector&lt;int&gt; b(a.size());
    for(int i = 0, len = a.size(); i &lt; len; i++) {
        int swapValue = (i + len - k) % len;
        b[swapValue] = a[i];
    }

    return b;
}

int main(){
    int n;
    int k;
    cin &gt;&gt; n &gt;&gt; k;
    vector&lt;int&gt; a(n);
    for(int a_i = 0;a_i &lt; n;a_i++){
        cin &gt;&gt; a[a_i];
    }
    vector&lt;int&gt; output = array_left_rotation(a, n, k);
    for(int i = 0; i &lt; n;i++)
        cout &lt;&lt; output[i] &lt;&lt; " ";
    cout &lt;&lt; endl;
    return 0;
}
Don't use:

using namespace std;


See: Why is “using namespace std” considered bad practice?

Only include the headers you need. Also organizing them by length of name does not seem to have any benefits. Personally I group them by function others sort them alphabetically. Pick something logical.

Pass large objects by const reference rather than value.

vector&lt;int&gt; array_left_rotation(vector&lt;int&gt; const&amp; a, int n, int k) {
                                      ///   ^^^^^^


If you pass by value as in the code above. The compiler needs to add code to copy the object from the main function into array_left_rotation().

Prefer pre-increment:

for(int i = 0, len = a.size(); i &lt; len; i++)
                                     // ^^^ prefer ++i


When using integers it makes no difference. But for other types it can potentially make a difference. So by using the pre-increment version you guarantee that you always use the most efficient version no matter what the type.

Not sure why we add len here:

int swapValue = (i + len - k) % len;


This is exactly the same as:

int swapValue = (i - k) % len;



Prefer to always use braces: '{' and '}' when you have a sub statements.

for(int i = 0; i &lt; n;i++) 
    cout &lt;&lt; output[i] &lt;&lt; " ";


I would have used this:

for(int i = 0; i &lt; n;i++) {
    cout &lt;&lt; output[i] &lt;&lt; " ";
}


Prefer \n over std::endl. THe only difference between the two is that std::endl will flush the stream. Since the code will automatically flush the stream at appropriate points (doing it manually usually results in efficiencies).