LC 0846 [M] Hand of Straights - ALawliet/algorithms GitHub Wiki
class Solution:
def isNStraightHand(self, hand: List[int], groupSize: int) -> bool:
if len(hand) % groupSize:
return False
count = defaultdict(int)
for n in hand:
count[n] += 1
minH = list(count.keys())
heapify(minH)
while minH:
first = minH[0] # first in group
for i in range(first, first + groupSize):
if i not in count:
return False
count[i] -= 1
if count[i] == 0: # 2
if i != minH[0]: # [1,2,3],[(1),_,3]
return False
heappop(minH)
return True