Coinbase | Onsite | Mahjong Tiles
Difficulty: EASYCategory: InterviewExperienceFrequency: 1Asked On 2022-05-09Added By Anonymous
Source: Link
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.
4.
Eg:-
1.Set of tiles : 11123
2.Output : True , as above set of tiles can be 11 (pair) and 123 (increasing triple)
3.Set of tiles : 11111
4.Output: True, as above set of tiles can be 11(pair) and 111(triple)
5.Set of tiles : 1123
6.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?