Problem · Hash Table
Maximum Elements With a Common Digit
Learn this problemProblem statement
An array numbers consists of N two-digit numbers.
A group of numbers can be chosen from the array only if all of them share at least one digit.
For example, 52, 25, and 55 can be chosen together because they share digit 5, while 11, 52, and 34 cannot be chosen together.
Return the maximum number of array elements that can be chosen together.
Implement solution(numbers).
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].