Merge two sorted arrays together Please review my answer for this interview question:

#include &lt;iostream&gt;
#include &lt;vector&gt;

std::vector&lt;int&gt; merge2Sorted ( std::vector&lt;int&gt; left, std::vector&lt;int&gt; right )
{
  //finger matching algo

  auto itLeft = left.begin();
  auto itRight = right.begin();

  auto itLeftEnd = left.end();
  auto itRightEnd = right.end();

  std::vector&lt;int&gt; result;
  result.reserve(std::max(left.size(),right.size())); 

  while ( itLeft != itLeftEnd &amp;&amp; 
          itRight != itRightEnd )
  {
    if ( *itLeft &lt; *itRight )
      result.push_back( *itLeft++ );
    else
      result.push_back( *itRight++ );
  }

  // copy rest of left array
  while ( itLeft != itLeftEnd )
    result.push_back(*itLeft++);

  // copy rest of right array
  while ( itRight != itRightEnd )
    result.push_back(*itRight++);

  return result;
}

int main ()
{
  std::vector&lt;int&gt; v1 = { 1,2,3,4,5,6,7,8,9,10 };
  std::vector&lt;int&gt; v2 = { -1,-2,0,3,7,9,11,12 };

  std::vector&lt;int&gt; v3 ( merge2Sorted ( v1, v2 ) );

  for ( auto&amp; i: v3 )
    std::cout &lt;&lt; i &lt;&lt; std::endl;
}
Pass your parameters by const reference to avoid a copy:

std::vector&lt;int&gt; merge2Sorted(std::vector&lt;int&gt; const&amp; left, std::vector&lt;int&gt; const&amp; right)
//                                             ^^^^^^                        ^^^^^^


You are not reservng enough

result.reserve(std::max(left.size(),right.size()));


The result size will eventually be the size of the sum of the two input arrays.

result.reserve(left.size() + right.size());


Your test for left and right can be simplified:

if ( *itLeft &lt; *itRight )
  result.push_back( *itLeft++ );
else
  result.push_back( *itRight++ );
}

// Simplified
// Though I am 50/50 on this one.
result.push_back( ( *itLeft &lt; *itRight ) ? *itLeft++ : *itRight++);


No point in flushing the stream after every print:

std::cout &lt;&lt; i &lt;&lt; std::endl;

                  ^^^^^^^^^^  prefer '\n' unless you really want to force a flush.

std::cout &lt;&lt; i &lt;&lt; '\n';