Winning Draws for a Mahjong Hand
Problem statement
You have 13 Mahjong tiles. Each tile has a rank from 1 through 9. A complete 14-tile hand is winning when all tiles can be divided into exactly four three-tile groups and one two-tile pair. A group is either three equal ranks or three consecutive ranks; the pair is two equal ranks.
For every rank from 1 through 9, consider drawing one more tile of that rank. Return all ranks whose draw makes the hand winning, in increasing order. A physical deck contains at most four tiles of each rank, so a rank already appearing four times cannot be drawn. Groups and the pair must use each of the 14 tiles exactly once.
Function
winningDraws(tiles: int[]) → int[]Examples
Example 1
tiles = [1,1,1,2,2,2,3,3,3,4,4,4,5]return = [2,3,4,5,6]Drawing 5 gives the obvious partition 111, 222, 333, 444, and pair 55. Other listed draws permit a different split using consecutive groups.
Example 2
tiles = [1,2,2,3,4,4,4,6,7,7,9,9,9]return = []No available fourteenth rank permits a partition into four groups and a pair.
Constraints
tiles.length == 13.1 <= tiles[i] <= 9.- Each rank appears at most four times in the given hand.