Maximum Elements With a Common Digit
Learn this problemProblem statement
You are given an array numbers of length N. A set of array elements can be chosen together if the chosen elements share at least one common digit.
For example, 52, 25, and 55 can be chosen together because they share digit 5, but 11, 52, and 34 cannot.
What is the maximum number of array elements that can be chosen together?
Write a function solution(numbers) that, given an array numbers of length N, returns the maximum number of elements that can be chosen.
Source note: The screenshot is missing part of the question, but the examples are clear enough for practice. If you know the full original version, feel free to tell us; we'll update it when we find a clearer source. 🦤
Function
solution(numbers: int[]) → intExamples
Example 1
numbers = [52, 25, 11, 52, 34, 55]return = 4Elements 52, 25, 52, and 55 can be chosen.
Example 2
numbers = [71, 23, 57, 15]return = 2It is possible to choose at most two elements.
Example 3
numbers = [11, 33, 55]return = 1No two numbers share any digit.
Example 4
numbers = [90, 90, 90]return = 3All numbers can be chosen.
Constraints
Nis an integer within the range[1..100].- Each element of array
numbersis an integer within the range[10..99].
More Google problems
- Deduplicate Logs: Keep FirstONSITE INTERVIEW · Seen Jul 2026
- Deduplicate Logs: Keep LatestONSITE INTERVIEW · Seen Jul 2026
- Find a Template Across Binary-Tree LeavesONSITE INTERVIEW · Seen Jul 2026
- Maximum Programmer-Problem MatchingONSITE INTERVIEW · Seen Jul 2026
- Minimum Direction ViolationsONSITE INTERVIEW · Seen Jul 2026
- Stream Latest Log VersionsONSITE INTERVIEW · Seen Jul 2026
- Stream Unique Logs in Timestamp OrderONSITE INTERVIEW · Seen Jul 2026
- Top-K IP Addresses from File RecordsONSITE INTERVIEW · Seen Jul 2026