Finding the intersection of two sets of integers
Let's look at these two nested loops. How many times does the loop body need to be executed?

for(x = 0; x &lt; n; x++)
{
    for(i = 0; i &lt; m; i++)
    {
        /* loop body ... */
    }
}


The loop body gets executed \$ nm \$ times. But the problem statement says that we have \$ 1 \le n, m \le 10^6 \$, so in the worst case \$ n = m = 10^6 \$ and so the loop body gets executed \$ 10^{12} \$ times. There's no way to do that in just 3 seconds!

So you need to find a different algorithm, one that doesn't try to examine every pair of elements.

How might you do that? Well, here are two ideas:


Sort the two arrays, and then output the intersection by merging the sorted arrays.
Store the first input set in a data structure that has efficient lookup, for example a hash table or a radix tree, and then look up the numbers in the second input set.