Practice Two Out of Three
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Return each distinct value that appears in at least two of nums1, nums2, and nums3. The output order is unrestricted. Several copies inside a single array still represent presence in only that one array. Practice approach: Deduplicate each array with a set, then count how many of the three sets contain each value. Include values whose count is at least two. This prevents duplicates in one array from producing false matches. With T input entries, expected time is O(T); the allowed value range also permits a fixed-size presence-bit table.
Source: Two Out of Three on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
nums1 = [1,1,3,2], nums2 = [2,3], nums3 = [3]
[3,2]
# Example 2
nums1 = [3,1], nums2 = [2,3], nums3 = [1,2]
[2,3,1]
# Example 3
nums1 = [1,2,2], nums2 = [4,3,3], nums3 = [5]
[]
Constraints
Related LeetCode Problems
Practice more problems similar to Two Out of Three.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.