Deal Into Straights
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
0 <= len(cards) <= 1001 <= cards[i] <= 10001 <= size <= 10
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Greedy problems
- Fewest Candies by RatingMedium
- Fewest Door VisitsMedium
- Fewest Flips to Balance BracketsMedium
- Fewest Increments to Distinct ValuesMedium
- Fewest Jumps to the EndMedium
- Fewest PlatformsMedium
- Fewest Routers for a CorridorMedium
- Jump GameMedium