Find largest digit-sharing subset
Company: Google
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Take-home Project
Quick Answer: This question evaluates a candidate's ability to reason about digit-based frequency analysis and efficient counting on arrays, testing competencies in combinatorics and algorithmic optimization for grouping elements by shared features.
Constraints
- 1 <= N (the array may also be empty, for which the answer is 0)
- Each element is an integer between 10 and 99 inclusive (exactly two decimal digits)
- Duplicate values are allowed and counted independently
- The algorithm must be efficient for large N (linear time)
Examples
Input: ([52, 25, 55],)
Expected Output: 3
Explanation: All three numbers contain the digit 5, so the entire array forms one valid group of size 3.
Input: ([11, 52, 34],)
Expected Output: 1
Explanation: No single digit appears in more than one of these numbers, so the best valid group is a single element.
Input: ([13, 24, 57, 68, 90],)
Expected Output: 1
Explanation: Every number uses a distinct pair of digits; no digit is shared by two numbers, so the answer is 1.
Input: ([99],)
Expected Output: 1
Explanation: A single element is trivially a valid group.
Input: ([],)
Expected Output: 0
Explanation: An empty array has no elements, so the maximum group size is 0.
Input: ([22, 22, 22, 22],)
Expected Output: 4
Explanation: All four copies contain digit 2; duplicates count independently, giving a group of size 4.
Input: ([15, 51, 16, 61, 71, 17, 23, 24],)
Expected Output: 6
Explanation: Digit 1 appears in 15, 51, 16, 61, 71, and 17 — six numbers — the largest digit tally.
Input: ([10, 20, 30, 40, 50, 60, 70, 80, 90],)
Expected Output: 9
Explanation: Every number contains the digit 0, so all nine form one valid group.
Hints
- A group is valid iff all its members share one common digit. So you never need to consider arbitrary subsets — just fix the shared digit.
- For each digit d in 0..9, count how many array elements contain d. The largest such count is the answer.
- Extract a number's two digits with tens = x // 10 and ones = x % 10 (or use the string representation). Use a set per number so a number like 55 is not double-counted for digit 5.
- For a non-empty array the answer is at least 1, since any single element is trivially a valid group.