Hand of Straights
Problem Statement
Alice has a hand of cards. Each card shows a number. She wants to split all of her cards into groups of exactly groupSize cards, where the numbers in each group are consecutive, like 3, 4, 5.
Return true if she can do this, and false if not.
An array hand of card values, and an integer groupSize.
true if the cards can be split into groups of consecutive values, otherwise false.
Split into [1,2,3], [2,3,4] and [6,7,8].
Five cards can't be split into groups of four.
Two copies of 3 are fine: [1,2,3] and [3,4,5].
- β’ 1 β€ hand.length β€ 10^4
- β’ 0 β€ hand[i] β€ 10^9
- β’ 1 β€ groupSize β€ hand.length
Pattern Recognition Clues
Recognising these key signals in the problem description immediately identifies the pattern:
Approach Complexity Ladder
Backtrack: try every card value as the start of the next group, and undo when a choice fails
Ordered map of counts; the smallest remaining card starts each group, which takes groupSize consecutive values
Pick any unused card as the start of the next group. The group is that value and the next groupSize β 1 values. Take those cards out, and recurse on what is left. If the rest fails, put the cards back and try another start.
Recognition rule for this sub-pattern:
Unlock Complete Visual Walkthrough & Optimal C++
The interactive animated dry-run player, optimized C++ implementation, state invariant derivations, and edge-case breakdown for this question are part of Brute2Best Pro. The anchor question of every sub-pattern is completely free.
First anchor question per pattern, Part 1 LLD & Module 1 C++ basics are 100% Free forever.
How this concept connects to System Design & C++ Systems
Top engineering interviews test whether you understand how algorithms like Greedy translate into production architectures and low-level memory mechanics.
Foundations: Object-Oriented Principles in C++23
Class invariants, pure virtual interfaces, and RAII smart pointers.
Food Delivery System (Zomato Architecture)
Real-world machine coding application of algorithms and design patterns.
Pointers vs References Deep Dive
Pointer arithmetic and memory layout under the hood.
Virtual Method Table (vtable) & Memory Layout
Polymorphism, vptr overhead, and multiple inheritance in memory.