The minus operator says that it "returns a list containing all elements of the original collection except the elements contained in the given elements collection". The MutableList.remove function only removes the first occurrence of an element, so this should remove the first occurrence of each element in the set. val seen = HashSet < Int >() val dupes : Set < Int > = ints .