Skip to content
BASA DSA

Hand of Straights

MediumGreedy

Return whether all cards can be split into groups of groupSize consecutive integer values. Equal cards are separate occurrences.

Example 1

Input
hand = [1,2,3,2,3,4]
groupSize = 3
Output
true

Explanation

Form [1,2,3] and [2,3,4], using every occurrence once.

Example 2

Input
hand = [1,2,4]
groupSize = 3
Output
false

Explanation

Missing 3 prevents a consecutive group of size three.

Example 3

Input
hand = [5,5]
groupSize = 1
Output
true

Explanation

Every card forms a valid size-one group, even with duplicates.

Constraints

  • 1 <= len(hand) <= 10000
  • 1 <= groupSize <= len(hand)
  • Values are nonnegative integers

Function contractisNStraightHandArguments: json, json
Loading draft…
SolutionRuns on your device
Loading draft…