FastPrepMaximum Elements With a Common Digit
Problem · Hash Table

Maximum Elements With a Common Digit

Learn this problem
EasyGoogle logoGoogleINTERNOA
See Google hiring insights

Problem 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[]) → int

Examples

Example 1

numbers = [52, 25, 11, 52, 34, 55]return = 4

Elements 52, 25, 52, and 55 can be chosen.

Example 2

numbers = [71, 23, 57, 15]return = 2

It is possible to choose at most two elements.

Example 3

numbers = [11, 33, 55]return = 1

No two numbers share any digit.

Example 4

numbers = [90, 90, 90]return = 3

All numbers can be chosen.

Constraints

  • N is an integer within the range [1..100].
  • Each element of array numbers is an integer within the range [10..99].

More Google problems

drafts saved locally
public int solution(int[] numbers) {
  // write your code here
}
numbers[52, 25, 11, 52, 34, 55]
expected4
checking account