Coinbase | Onsite | Mahjong Tiles
Anonymous User
4962

Given a set of tiles (represented by numbers from 0 - 9), a valid configuration of tiles for success at this game happens only when the entire set can be divided such that:

  1. There is at least 1 pair [e.g. - 9,9]
  2. There can be any number of triples. [e.g. - 1,1,1] . No. of triples can be 0 as well.
  3. There can be any increasing triple [e.g. - 1,2,3] . No. of increasing triples can be 0 as well.

Eg:-

  1. Set of tiles : 11123
    Output : True , as above set of tiles can be 11 (pair) and 123 (increasing triple)

  2. Set of tiles : 11111
    Output: True, as above set of tiles can be 11(pair) and 111(triple)

  3. Set of tiles : 1123
    Output: False , as the above set can be divided into a pair (11), but (23) are extra.

I tried branching on the above set, s.t. at each step we either pick a pair or not pick a pair, but my solution was not correct.

Can anyone please help what should be the correct approach for this problem?

Comments (29)