Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

hand =
groupSize =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

Greedily start sequences from the smallest available card.

Approach

Count occurrences. Iterate values in ascending order. If cnt[x] = c > 0, we must start c groups at x, so subtract c from x..x+groupSize-1.

Why it works

Any valid partition must place the smallest remaining card as the start of a group (it cannot appear later in a consecutive group).

Code
Loading...
Complexity
Time: O(n log n)
Space: O(n)
Solution
Updated: 2026-02-23

Idea

Greedily start sequences from the smallest available card.

Approach

Count occurrences. Iterate values in ascending order. If cnt[x] = c > 0, we must start c groups at x, so subtract c from x..x+groupSize-1.

Why it works

Any valid partition must place the smallest remaining card as the start of a group (it cannot appear later in a consecutive group).

Code
Loading...
Complexity
Time: O(n log n)
Space: O(n)