Skip to main content
Back to problems
Leetcode
Medium
Hash Maps
Arrays
Ordered Structures
Sorting
Google
Meta
Hand Of Straights

Determine whether a multiset of cards can be rearranged into groups of equal size where each group contains consecutive values.

Acceptance 0%
Also Available On
Other platform versions and source mappings for the same problem.
Problem Statement

You are given an array of integers representing cards in hand and an integer groupSize. Each card value may appear multiple times.

Rearrange the cards into groups so that:

  • Every group has exactly groupSize cards.
  • The cards in each group form a sequence of consecutive integers.
  • Every card must belong to exactly one group.

Return true if such a rearrangement is possible, otherwise return false.

This is a classic grouping problem where the order of the input does not matter, but the availability of each value does.

Input Format

  • hand: an array of integers representing card values.
  • groupSize: an integer specifying the required size of each group.

Output Format

Return a boolean indicating whether the cards can be partitioned into valid consecutive groups.

Constraints

  • 1 <= hand.length <= $10^{4}$
  • 0 <= hand[i] <= $10^{9}$
  • 1 <= groupSize <= hand.length
  • The same card value may appear multiple times.
Examples
Sample cases returned by the problem API.

Example 1

Input

hand = [1,2,3,6,2,3,4,7,8], groupSize = 3

Output

true

Explanation

One valid partition is [1,2,3], [2,3,4], and [6,7,8].

Example 2

Input

hand = [1,2,3,4,5], groupSize = 4

Output

false

Explanation

There are 5 cards, which cannot be split into groups of 4 cards each.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.