FunctionRacerProblemsRace

Deal Into Straights

MediumGreedyPython, JavaScript, TypeScript, Java, C++

cards lists the values on the cards in a hand, in no particular order. You want to deal the whole hand into groups of exactly size cards each, where every group is a straight: size consecutive integer values, such as 4, 5, 6 when size is 3. Every card must land in exactly one group.

Return True if the hand can be dealt this way, otherwise False. An empty hand returns True.

Example 1

cards [1,2,3,6,2,3,4,7,8]
size 3
returns true

The hand deals into 1 2 3, 2 3 4 and 6 7 8.

Example 2

cards [1,2,3,4,5]
size 4
returns false

Five cards cannot form groups of four.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Greedy problems