# 2032. Two Out of Three

![](https://4272748102-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LekNH5IywF8mjBxFcnu%2Fuploads%2FWe9LRvKMIjO6iMthDvji%2Fimage.png?alt=media\&token=1230a363-3626-4be8-bac8-3062cd4bd167)

![](https://4272748102-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LekNH5IywF8mjBxFcnu%2Fuploads%2FG2GkG9lRVDcbFmJJB4Ct%2Fimage.png?alt=media\&token=7eb95b80-0ab8-403d-a37e-7fbbda3ba03f)

time: O(n1+n2+n3)

space: O(n), n <= (n1+n2+n3)

```java
class Solution {
    public List<Integer> twoOutOfThree(int[] nums1, int[] nums2, int[] nums3) {
        List<Integer> res = new ArrayList<>();
        
        Map<Integer, Integer> map = new HashMap<>();
        Set<Integer> set1 = new HashSet<>();
        Set<Integer> set2 = new HashSet<>();
        Set<Integer> set3 = new HashSet<>();
        for (int n : nums1) {
            set1.add(n);
        }
        for (int n : nums2) {
            set2.add(n);
        }
        for (int n : nums3) {
            set3.add(n);
        }

        
        for (int n : set1) {
            map.put(n, 1);
        }
        for (int n : set2) {
            map.put(n, map.getOrDefault(n, 0)+1);
        }
        for (int n : set3) {
            map.put(n, map.getOrDefault(n, 0)+1);
        }
        map.forEach((key, value) ->{
            if (value >= 2) {
                res.add(key);
            }
        });
        return res;
    }
}

/*
set

map 
1 1
2 1
4 1
3 1
5 1

[3,1], nums2 = [2,3], nums3 = [1,2]

3 2
2 2
1 2

nums1 = [1,1,3,2], nums2 = [2,3], nums3 = [3]

3 3
2 2
1
1 1
2 1
4 1
3 


*/
```
