Empty the output array before intersection
Update the code with comment