Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Hand of Straights

Medium
greedyhash-tablesorting

Alice has a hand of cards and wants to rearrange them into groups of exactly k consecutive cards. Return true if she can.

Input

  • Line 1: space-separated card values
  • Line 2: integer k

Output: true or false.

Example 1
Input:
1 2 3 6 2 3 4 7 8
3
Output:
true

[1,2,3] [2,3,4] [6,7,8].

Example 2
Input:
1 2 3 4 5
4
Output:
false

5 cards can't split into groups of 4.

Constraints

  • 1 ≤ hand.length ≤ 10^4
  • 1 ≤ k ≤ hand.length
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.