easyArrays & HashingPure DSA~12 min
Shared Audience Intersection
Two marketing segments each list the user IDs they target. To find users eligible for a joint campaign, return the distinct IDs present in both segments.
Problem
Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must be unique, and the result may be in any order.
Input
Two arrays nums1, nums2 (0 ≤ length ≤ 1000), values in [0, 10^4].
Output
An array of the distinct values present in both inputs.
Constraints
- Each result element appears once, regardless of input multiplicity
- 0 ≤ nums1.length, nums2.length ≤ 1000
- Order of the result does not matter
Examples
Example 1
Input
nums1 = [1,2,2,1], nums2 = [2,2]
Output
[2]
2 is the only shared value; duplicates collapse to one entry.
Example 2
Input
nums1 = [4,9,5], nums2 = [9,4,9,8,4]
Output
[9,4]
9 and 4 appear in both; order is arbitrary.