easyArrays & HashingPure DSA~11 min
Common Followers
A 'mutual connections' feature intersects two users' follower id lists. Return the set of follower ids that appear in both, with no duplicates.
Problem
Given two integer arrays a and b, return an array of their distinct common values (the set intersection), in any order.
Input
Arrays a and b of lengths m and n (0 ≤ m, n ≤ 10^5), values in [-10^9, 10^9].
Output
An array of the distinct values present in both inputs.
Constraints
- 0 ≤ m, n ≤ 100,000
- Each result value appears once
- Order of the output does not matter
Examples
Example 1
Input
a = [1, 2, 2, 1], b = [2, 2]
Output
[2]
Only 2 is common; duplicates collapse to a single entry.
Example 2
Input
a = [4, 9, 5], b = [9, 4, 9, 8, 4]
Output
[4, 9]
4 and 9 appear in both arrays.