My first instinct was to just check pairwise digit overlap and greedily build groups, which completely fell apart once I thought about transitivity.
Model the problem as a graph where each number is a node and edges connect numbers sharing at least one digit. The task reduces to finding the largest connected component in this graph. Use union-find or BFS/DFS to compute component sizes efficiently.
Pro tip: Clarify that the group must be connected (each number shares a digit with at least one other in the group), not just that every number shares a digit with some common number. This distinction is crucial and often missed.
Confirm that the group must be connected: every number shares at least one digit with at least one other number in the group. This means the group forms a connected component in the digit-sharing graph.
Create nodes for each number. Add an edge between two numbers if they share at least one digit (0-9). The problem then asks for the size of the largest connected component.
Use Union-Find (Disjoint Set Union) or BFS/DFS to find connected components. Union-Find is efficient for up to 100 elements and easy to implement.
Instead of checking all pairs (O(n^2)), group numbers by each digit they contain. For each digit, union all numbers that have that digit. This reduces time complexity.
After processing all digits, find the size of each connected component and return the maximum. Handle edge cases like empty array or single element.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.