Math Fundamentals18 sections · 814 units
Open in Course

Difference - The Idea

Two-way difference

You need to compute ABA \setminus B and BAB \setminus A. For each, iterate through the first set and check if elements are absent from the second.

Convert both arrays to sets to remove duplicates. Then filter elements in set AA that are not in set BB, and vice versa.

This is a straightforward application of set difference. The operation is not symmetric, so you must compute both directions.