Find largest subset sharing a common digit
Company: Google
Role: Software Engineer
Category: Coding & Algorithms
Interview Round: Take-home Project
Quick Answer: This question evaluates array-processing and grouping skills, focusing on identifying shared-digit membership among two-digit integers and aggregating counts to determine the largest compatible subset.
Constraints
- 1 <= N <= 100
- 10 <= nums[i] <= 99
- Each nums[i] is a strictly two-digit integer
Examples
Input: ([52, 25, 11, 52, 34, 55],)
Expected Output: 4
Explanation: Digit 5 appears in 52, 25, 52, and 55, so the largest valid subset has size 4.
Input: ([71, 23, 57, 15],)
Expected Output: 2
Explanation: The best possible size is 2. For example, 71 and 57 share digit 7. Also, 71 and 15 share 1, and 57 and 15 share 5.
Input: ([11, 33, 55],)
Expected Output: 1
Explanation: No digit appears in more than one number, so you can only choose one element.
Input: ([90, 90, 90],)
Expected Output: 3
Explanation: All three numbers contain digit 9 and also digit 0, so all elements can be selected.
Input: ([10],)
Expected Output: 1
Explanation: With only one number, the maximum valid subset size is 1.
Input: ([10, 20, 30, 44, 45],)
Expected Output: 3
Explanation: Digit 0 appears in 10, 20, and 30, giving a subset of size 3. No other digit appears in more than 3 numbers.
Hints
- Any valid subset is determined by a single digit from 0 to 9. Try checking how many numbers contain each digit.
- Be careful with numbers like 11 or 55: the same digit appears twice, but that number should only be counted once for that digit.