The Split Array into Consecutive Subsequences interview question asks you to determine if a sorted array can be partitioned into one or more subsequences such that each subsequence consists of consecutive integers and has a minimum length of three. This problem combines array partitioning with strict length and value constraints, making it a complex logic puzzle.
Companies like Amazon and Google use this Split Array into Consecutive Subsequences coding problem to test a candidate's ability to think several steps ahead. It requires balancing the need to satisfy the "minimum length 3" rule while still using up all the numbers in the array. It evaluates your skills in Greedy logic and your ability to use Hash Tables or Heaps to track the state of multiple sequences simultaneously.
The most efficient approach is a Greedy strategy using two Hash Maps:
frequency map to count how many of each number remain.hypothetical (or needs) map to track which numbers are needed to extend existing subsequences.
For each number, you first try to add it to an existing subsequence that needs it. If that's not possible, you try to start a new subsequence of length 3 (checking if the next two consecutive numbers are available). If neither is possible, you return false.Array: [1, 2, 3, 3, 4, 5]
[1,2,3].[1,2,3], [3,4,5].
All numbers used. Result: True.If the array was [1, 2, 3, 3, 4]:
For greedy problems, always consider the "priority of choices." In this problem, the priority is: 1. Extend an existing sequence. 2. Start a new sequence of length 3. This hierarchy ensures that you don't leave "dangling" sequences that are too short to be valid.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Avoid Flood in The City | Medium | Solve | |
| Maximize Y‑Sum by Picking a Triplet of Distinct X‑Values | Medium | Solve | |
| Reduce Array Size to The Half | Medium | Solve | |
| Maximal Score After Applying K Operations | Medium | Solve | |
| Maximum Average Pass Ratio | Medium | Solve |