I was asked this question in an interview for a start-up:
Suppose you have a stream of numbers and you need to find the duplicates present in the stream of numbers. How would you use the fact that this program will run on a multi-core system to make this faster.
I suggested that every time a number comes, create a new thread and pass the new number to the newly created thread. Each thread can access the set to check if the number exists or not. In case it does not exist in the set, it can take a lock and insert it after it.
This approach would be slower and I suggested making a lock-free set (possibly using atomic data types in some way).
Is there any other approach that would exploit the multi-core property to run faster?