# 2032. Two Out of Three

• Time: $O(n)$
• Space: $O(100) = O(1)$
  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 class Solution { public: vector twoOutOfThree(vector& nums1, vector& nums2, vector& nums3) { vector ans; vector count(101); for (const vector& nums : {nums1, nums2, nums3}) update(count, nums); for (int i = 1; i <= 100; ++i) if (count[i] >= 2) ans.push_back(i); return ans; } private: void update(vector& count, const vector& nums) { for (const int num : unordered_set(nums.begin(), nums.end())) ++count[num]; } }; 
  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 class Solution { public List twoOutOfThree(int[] nums1, int[] nums2, int[] nums3) { List ans = new ArrayList<>(); int[] count = new int[101]; for (int[] nums : new int[][] {nums1, nums2, nums3}) update(count, nums); for (int i = 1; i <= 100; ++i) if (count[i] >= 2) ans.add(i); return ans; } private void update(int[] count, int[] nums) { for (final int num : Arrays.stream(nums).boxed().collect(Collectors.toSet())) ++count[num]; } } 
 1 2 3 4 5 6 class Solution: def twoOutOfThree(self, nums1: List[int], nums2: List[int], nums3: List[int]) -> List[int]: count = collections.Counter() for nums in nums1, nums2, nums3: count.update(set(nums)) return [i for i, c in count.items() if c >= 2]