Checking "have I seen this before?" with a list is O(n) per check, which makes the whole solution O(n²). A HashSet answers it in O(1) average and keeps only unique values. Use it to detect duplicates, find the common elements of two arrays, or count distinct values. When you also need how many times each value appeared, switch to a HashMap.