We here at Company X believe that math is not useful unless it is bespoke, hand-made, artisanal. Please pretend that set theory does not yet exist in this universe, and describe to us the smell of the algorithm you might write to solve this problem.
You just described the "what", not the "how". The implied context is algorithmic. It'd be like answering a question about sorting lists with "use sort()" - true enough in practical terms, but smart-arsey and deliberately avoiding the meat of the question.