← Questions
Largest subset of two-digit numbers sharing a digit
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Google's HackerRank assessment, last asked Feb 2026. It tests counting and arrays.
An array holds only two-digit integers (10 to 99). Choose as many elements as you can so that all chosen numbers share at least one common digit: there is some digit d from 0 to 9 that appears in every chosen number, in the tens or the ones place. Return the largest possible count.
Interface
Unless you agree on a different interface with the interviewer, assume:
-
largest_shared_digit_subset(nums: list[int]) -> int— duplicates count as separate elements.
Example
largest_shared_digit_subset([52, 25, 11, 52, 34, 55]) -> 4 # 52, 25, 52, 55 all contain 5
largest_shared_digit_subset([71, 23, 57, 15]) -> 2 # e.g. 71 and 57 share 7
largest_shared_digit_subset([11, 33, 55]) -> 1 # no digit is shared
largest_shared_digit_subset([90, 90, 90]) -> 3 # all contain 9 (and 0)
Constraints
-
1 <= len(nums) <= 100; every element is between 10 and 99.
Clarifying questions
- Do duplicate numbers count separately?
- Is a number like 55 counted once or twice for digit 5? (Once.)
- Does 0 count as a digit for numbers like 90?
What a strong answer covers
- The key observation: a valid subset is defined by one digit, so the answer is the maximum over the 10 digits of how many numbers contain that digit.
- One pass with 10 counters; for each number, add one to each of its distinct digits (so 55 adds 1 to digit 5, not 2).
O(n)time,O(1)space. - Why searching over subsets is unnecessary.
- Tests: a single number, repeated digits, all duplicates, digit 0.
Follow-ups
- Numbers have any number of digits.
- Return the chosen elements, not only the count.
- The chosen numbers must share at least two digits.
Where it's asked
- Google · HackerRank assessment · Last asked Feb 202690 min · Two problems on HackerRank · Some early-career assessments enable the built-in assistant; others forbid AI. The invitation says which.
What it tests
counting · arrays
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
