← Google Interview Insights

Google·Software Engineer·Online Assessment (OA)·Intermediate

Intermediate
Jul 2026

Summary

Google SWE coding question, pretty straightforward digit-matching problem but the edge cases tripped me up more than I expected.

Questions Asked (1)

Q1

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

Algorithms & Data Structures
Author's notes

My first instinct was to brute-force every possible digit 0-9, count how many numbers in the list contain that digit, then return the max.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify that each number is two-digit and we need the largest subset sharing at least one common digit. Since digits are only 0-9, count how many numbers contain each digit and return the maximum count. Mention that this is O(n) time and O(1) space.

Pro tip: Proactively discuss edge cases like numbers with repeated digits (e.g., 11) and leading zeros (e.g., 05), and confirm whether the list can be empty or contain non-two-digit numbers.

1. Clarify the problem

Confirm that 'share at least one digit' means any common digit, and that numbers are exactly two-digit. Ask about input size, duplicates, and edge cases.

2. Identify the key insight

Recognize that the common digit must be one of the 10 possible digits (0-9). Therefore, the maximum subset size is the maximum frequency of any digit across all numbers.

3. Design the algorithm

Initialize an array of size 10 to count digit occurrences. For each number, extract its two digits and increment the counts for each distinct digit.

4. Analyze complexity

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

5. Handle edge cases

Discuss handling of numbers with repeated digits (count once per number), leading zeros, empty input, and potential duplicates.

Key Points to Mention

  • The common digit must be one of 0-9, so we can count occurrences per digit.
  • For each number, consider each distinct digit only once to avoid double-counting.
  • The answer is the maximum count across all digits.
  • Time complexity is O(n) and space complexity is O(1).
  • Edge cases: repeated digits (e.g., 11), leading zeros (e.g., 05), empty list.
  • If the list is empty, return 0.

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