PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This Coding & Algorithms question evaluates algorithmic reasoning about combinatorial search and multiset partitioning, testing the candidate's ability to represent and manipulate tile counts and validate pattern-based groupings.

  • medium
  • Google
  • Coding & Algorithms
  • Software Engineer

Determine if a 14-tile hand is winning

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given an integer array `tiles` of length 14 representing a Mahjong-like hand. Each integer is a tile value from 1 to 9 (single suit). You may reorder the tiles. A hand is **winning** if it can be partitioned into: - **1 pair**: two identical tiles, and - **4 melds** (each meld uses 3 tiles), where each meld is either: - a **triplet**: three identical tiles (e.g., 7,7,7), or - a **sequence**: three consecutive values (e.g., 2,3,4). Each tile can be used at most once. Return `true` if the hand is winning, otherwise return `false`. Assumptions/constraints: - `tiles.length == 14` - `1 <= tiles[i] <= 9` - Each value can appear multiple times (as in a real tile set).

Quick Answer: This Coding & Algorithms question evaluates algorithmic reasoning about combinatorial search and multiset partitioning, testing the candidate's ability to represent and manipulate tile counts and validate pattern-based groupings.

You are given an integer array `tiles` of length 14 representing a Mahjong-like hand from a single suit. Each value is between 1 and 9, and you may reorder the tiles. A hand is **winning** if all 14 tiles can be partitioned into exactly: - **1 pair**: two identical tiles - **4 melds**: each meld uses 3 tiles and is either: - a **triplet**: three identical tiles - a **sequence**: three consecutive values Each tile must be used exactly once. Return `True` if the hand is winning, otherwise return `False`.

Constraints

  • `tiles.length == 14`
  • `1 <= tiles[i] <= 9`
  • Tiles may contain duplicates

Examples

Input: ([1,1,1,2,3,4,2,3,4,5,6,7,9,9],)

Expected Output: True

Explanation: A valid partition is pair `9,9`, triplet `1,1,1`, sequence `2,3,4`, sequence `2,3,4`, and sequence `5,6,7`.

Input: ([2,2,2,3,3,3,4,4,4,5,5,5,9,9],)

Expected Output: True

Explanation: Use pair `9,9` and four triplets: `2,2,2`, `3,3,3`, `4,4,4`, `5,5,5`.

Input: ([1,1,2,2,3,3,4,5,5,5,6,7,8,9],)

Expected Output: True

Explanation: The correct pair is `5,5`. The remaining tiles form sequences `1,2,3`, `1,2,3`, `4,5,6`, and `7,8,9`.

Input: ([1,1,1,1,2,3,4,5,6,7,8,8,9,9],)

Expected Output: False

Explanation: No matter which pair you choose, the remaining 12 tiles cannot be fully split into four valid triplets/sequences. This case heavily uses boundary values 1 and 9.

Hints

  1. Count how many times each value from 1 to 9 appears instead of working directly with the raw array.
  2. Try every possible pair first. After removing a pair, recursively remove the smallest remaining tile as part of either a triplet or a sequence.
Last updated: Apr 19, 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)