Largest Digit Group
GoogleEasy
You are given a list nums of two-digit numbers. A digit appears in a number if it is its tens digit or its units digit, so 52 has the digits 5 and 2. A repeated number is a separate entry for each time it appears.
Part 1: Largest valid group
A group is any selection of entries from nums. A group is valid when at least one digit appears in every member of the group. The members do not need to be next to each other, and the order of the digits does not matter. A single entry is always a valid group.
Return the size of the largest valid group. A digit that appears twice in one number, like the two 1s in 11, still counts only once for that number.
- Example 1
- nums
[52,25,55,11,34]- Output
3
Why: Digit 5 appears in 52, 25 and 55, so a group of 3 shares it. Digit 2 reaches only 52 and 25, and digit 1 reaches only 11.
- Example 2
- nums
[11,21,31,41,16,17,18,34,57]- Output
7
Why: Digit 1 appears in 11, 21, 31, 41, 16, 17 and 18, which is 7 numbers.
11counts once even though it has two 1s.
Constraints
1 <= len(nums) <= 10010 <= nums[i] <= 99