The Divide Array in Sets of K Consecutive Numbers interview question asks you to determine if an array can be partitioned into sets of size where each set contains consecutive integers. For example, if , a valid set could be [4, 5, 6]. Every number in the input array must be used exactly once.
Microsoft and Google use this problem to evaluate a candidate's proficiency with Hash Tables and Greedy interview patterns. It tests whether you can identify the "bottleneck" (the smallest available number) and realize that it must be the start of a consecutive sequence. It evaluation your ability to manage counts and efficiently verify group existence in a collection.
This problem follows a Greedy approach with Frequency Counting.
TreeMap (to keep keys sorted).false.true.Array: [1, 2, 3, 3, 4, 4, 5, 6], .
[1, 2, 3, 4].[3, 4, 5, 6].true.When a problem involves "consecutive" elements, sorting is almost always involved. A TreeMap or a sorted list of unique keys combined with a Hash Map is the standard way to implement a greedy "start from the bottom" strategy.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Hand of Straights | Medium | Solve | |
| Find Original Array From Doubled Array | Medium | Solve | |
| Array of Doubled Pairs | Medium | Solve | |
| Largest Values From Labels | Medium | Solve | |
| Maximum Number of Integers to Choose From a Range I | Medium | Solve |