Skip to content
Decoder

Hand of Straights

Medium

Problem

You hold a hand of cards, hand[i] being the value on card i. Decide whether you can split all of the cards into groups of exactly group_size cards, where each group is a run of consecutive values (like 4, 5, 6). Return true or false.

Example 1

Input
hand = [1, 2, 3, 6, 2, 3, 4, 7, 8], group_size = 3
Output
true
Why
[1,2,3] [2,3,4] [6,7,8]

Example 2

Input
hand = [1, 2, 3, 4, 5], group_size = 4
Output
false
Why
5 cards cannot fill groups of 4

Constraints

  • 1 <= hand.length <= 10^4
  • 0 <= hand[i] <= 10^9
  • 1 <= group_size <= hand.length

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.