Skip to content

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.

Easy#2032
LeetCode Problem

Two Out of Three

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

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

# Example 2

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

# Example 3

Input
nums1 = [1,2,2], nums2 = [4,3,3], nums3 = [5]
Output
[]

Constraints

1 <= nums1.length, nums2.length, nums3.length <= 100
1 <= nums1[i], nums2[j], nums3[k] <= 100

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.