It's cute but not good enough, and as you might have guessed from my other posts, whenever it's about increasing speed, think about how can you use hashmap, since they give you the superpower of accessing entries in O(1) time. In this case a Set will also do the work.

HashMaps: O(n) time and O(n) space.
So we shall create an object, add each element to them and check if we've seen that element before, if we've seen the element before, then add it to result.

But you might be wondering why to bother doing this when we can achieve the same using hashmap.

In order to run it in O(n) time and O(1) space and impress your interviewer and crush, let's make a modification, instead of creating a new boolean array, we shall mark the element as negative. Let's see how: