Notice Period

Straight Hands

medium

A card club plays a game where every player must hold "straights": groups of exactly size cards with consecutive values, e.g. [4, 5, 6] for size 3.

You're handed the full deal as a list cards (values may repeat). Return True if the entire deal can be partitioned into such straights with no card left over, False otherwise.

Example 1
in cards = [1, 2, 3, 6, 2, 3, 4, 7, 8], size = 3
out True
Straights: [1,2,3], [2,3,4], [6,7,8].
Example 2
in cards = [1, 2, 3, 4, 5], size = 4
out False
5 cards can't split into groups of 4.
Constraints
  • · 1 <= len(cards) <= 10^4
  • · 0 <= cards[i] <= 10^9
  • · 1 <= size <= len(cards)
similar problem on LeetCode ↗
solution.pyloading python…
test results
Hit ▶ Run to test your code against the visible cases.