NewProject Coding is here — build features and fix bugs in real codebases with an AI assistantSee what's new

A hand consists of tiles represented by an integer array tiles. The order of the tiles does not matter, and a value may occur any number of times.

A winning hand can be partitioned into exactly four triples and exactly one pair, with every tile belonging to one group. A triple contains either three equal values or three consecutive values, and a pair contains two equal values.

Return whether the hand is winning.

Constraints:

  • tiles.length = 14
  • 1 ≤ tiles[i] ≤ 9

Example 1:

Input: tiles = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 9, 9, 9] Output: true Explanation: A valid partition is [1, 2, 3], [1, 2, 3], [5, 5, 5], [9, 9, 9], and the pair [4, 4].

Example 2:

Input: tiles = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5] Output: true

Example 3:

Input: tiles = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 8] Output: false


Accepted
2/2
Acceptance Rate100.0%
Test Cases
Input
tiles =
Output
Expected