← Google Interview Insights

Google·Software Engineer·Onsite - Coding / Algorithms·Intermediate

Intermediate
Jun 2026

Summary

Google SWE coding round with a grouping/digit-matching array problem. Pretty clean problem statement but the edge cases can sneak up on you if you're not careful about how you enumerate digits.

Questions Asked (1)

Q1

Given an array of two-digit numbers, find the maximum number of elements you can select such that all selected numbers share at least one common digit.

Algorithms & Data Structures
Author's notes

My first instinct was to sort or group by digit, which is roughly right, but I spent too long thinking about it as a set intersection problem across all pairs.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify that each number is two-digit (10-99) and that 'common digit' means at least one digit (0-9) appears in every selected number. Then, for each digit 0-9, count how many numbers contain that digit, and return the maximum count. This yields an O(n) solution with a small constant factor.

Pro tip: Mention that you can solve it in one pass by maintaining counts for each digit, and that the answer is simply the maximum frequency among digits. This shows you optimize for both time and space.

1. Clarify the problem

Confirm that numbers are two-digit, that 'common digit' means at least one digit shared by all selected numbers, and that we want the maximum subset size.

2. Identify the key insight

Realize that if a subset shares a common digit, that digit must be present in every number of the subset. So the problem reduces to finding the digit that appears in the most numbers.

3. Design the algorithm

Initialize an array of size 10 to zero. For each number, extract its tens and ones digits, and increment the counts for those digits (avoid double-counting if both digits are the same).

4. Compute and return the result

After processing all numbers, return the maximum value in the count array. This is the size of the largest subset sharing a common digit.

5. Analyze complexity

State that the algorithm runs in O(n) time and O(1) space (since the count array has fixed size 10), which is optimal.

Key Points to Mention

  • The problem reduces to finding the most frequent digit across all numbers.
  • Use a frequency array of size 10 to count occurrences of each digit.
  • Handle numbers where both digits are the same (e.g., 11) by counting the digit only once per number.
  • Time complexity is O(n) and space complexity is O(1).
  • Edge cases: empty array, all numbers sharing a digit, no common digit (but since each number has digits, there is always at least one digit with count ≥1).
  • Alternative approach: for each digit, filter numbers containing it and take the max size, but that is less efficient.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.