Using HashSet instead of ArrayList. O(1) vs O(n)