Calculate difference of two ranges given
Make sure this is the signature they want. e.g. they do not expect the function to return vector, iterator or sthg. Also make sure they do not expect you to validate input. e.g. a1 &lt;= a2 etc... after that you can remove redundant conditionals, they are already present in the for loops. And you can replace ternary operators with std::min/max for a more idiomatic c++. otherwise I could not find any missed case or off-by-one bugs.

void findDiff(int a1,int a2, int a3, int a4)
{
   cout&lt;&lt;"("&lt;&lt;a1&lt;&lt;","&lt;&lt;a2&lt;&lt;") - ("&lt;&lt;a3&lt;&lt;","&lt;&lt;a4&lt;&lt;") = \n";

    for(int i=a1; i&lt;=std::min(a2, (a3-1)); i++) cout&lt;&lt;i&lt;&lt;"\t";

    for(int i=std::max(a1, (a4+1)); i&lt;=a2; i++) cout&lt;&lt;i&lt;&lt;"\t";

    cout&lt;&lt;"\n";
}