PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates array-processing and grouping skills, focusing on identifying shared-digit membership among two-digit integers and aggregating counts to determine the largest compatible subset.

  • Google
  • Coding & Algorithms
  • Software Engineer

Find largest subset sharing a common digit

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Interview Round: Take-home Project

You are given an array `nums` of length `N` (1 ≤ N ≤ 100). Every element is a **two-digit integer** between **10 and 99** (inclusive). Select as many elements as possible such that **all selected numbers share at least one common digit** (a digit from 0 to 9). In other words, there exists a digit `d` such that every selected number contains digit `d` in either its tens or ones place. Return the **maximum possible size** of such a selection. Examples: - Input: `[52, 25, 11, 52, 34, 55]` → Output: `4` (e.g., `{52, 25, 52, 55}` all contain digit `5`) - Input: `[71, 23, 57, 15]` → Output: `2` (e.g., `{71, 57}` share digit `7`) - Input: `[11, 33, 55]` → Output: `1` (no digit is shared by two numbers) - Input: `[90, 90, 90]` → Output: `3` (all share digit `9` or digit `0`) Constraints: - `1 ≤ N ≤ 100` - `10 ≤ nums[i] ≤ 99` and each `nums[i]` is strictly two digits.

Quick Answer: This question evaluates array-processing and grouping skills, focusing on identifying shared-digit membership among two-digit integers and aggregating counts to determine the largest compatible subset.

You are given an array nums of length N, where each element is a two-digit integer from 10 to 99 inclusive. Choose as many elements as possible so that all chosen elements share at least one common digit. That means there must exist some digit d from 0 to 9 such that every selected number contains d in either its tens place or ones place. Return the maximum possible number of elements you can choose. Notes: - Duplicate numbers count as separate elements. - A number like 11 contains digit 1, but it should only be counted once for digit 1.

Constraints

  • 1 <= N <= 100
  • 10 <= nums[i] <= 99
  • Each nums[i] is a strictly two-digit integer

Examples

Input: ([52, 25, 11, 52, 34, 55],)

Expected Output: 4

Explanation: Digit 5 appears in 52, 25, 52, and 55, so the largest valid subset has size 4.

Input: ([71, 23, 57, 15],)

Expected Output: 2

Explanation: The best possible size is 2. For example, 71 and 57 share digit 7. Also, 71 and 15 share 1, and 57 and 15 share 5.

Input: ([11, 33, 55],)

Expected Output: 1

Explanation: No digit appears in more than one number, so you can only choose one element.

Input: ([90, 90, 90],)

Expected Output: 3

Explanation: All three numbers contain digit 9 and also digit 0, so all elements can be selected.

Input: ([10],)

Expected Output: 1

Explanation: With only one number, the maximum valid subset size is 1.

Input: ([10, 20, 30, 44, 45],)

Expected Output: 3

Explanation: Digit 0 appears in 10, 20, and 30, giving a subset of size 3. No other digit appears in more than 3 numbers.

Hints

  1. Any valid subset is determined by a single digit from 0 to 9. Try checking how many numbers contain each digit.
  2. Be careful with numbers like 11 or 55: the same digit appears twice, but that number should only be counted once for that digit.
Last updated: Apr 29, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Solve Rooms and Top-K Streams - Google (medium)
  • Find Containing Range - Google (medium)
  • Rearrange Tasks With Cooldown - Google (medium)
  • Implement Employee Management and Expression Evaluation - Google (medium)
  • Solve Three Array and Matrix Path Problems - Google (medium)