Split Shuffled Ticket Numbers Into Runs of Consecutive Groups
Last updated: November 29, 2026
Quick Overview
Given a multiset of integer ticket numbers and a group size W, return True if they can be split into groups of exactly W consecutive numbers (for example 3, 4, 5), each ticket used exactly once.
0
0
0 solved
Given a multiset of integer ticket numbers and a group size W, return True if they can be split into groups of exactly W consecutive numbers (for example 3, 4, 5), each ticket used exactly once.
Framed as batching sequential ticket or shard IDs into contiguous ranges, this is a Google onsite greedy plus hashing problem. The interviewer wants the insight that the smallest remaining number must start a group, and checks the efficiency of how you consume counts.
What the Interviewer Expects
- Checks that the count is divisible by W
- Argues the smallest remaining number must start a group
- Uses a count map plus sorted unique keys
- Consumes W counts per group start, failing on any shortage
- States O(n log n) time
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Return the actual groups.
- Improve to O(n) expected time when numbers are dense.
- What if groups may have any length of at least 3 (split array into consecutive subsequences)?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: list
ticketsof integers (duplicates allowed) and integerW >= 1. - Output: True if the tickets can be partitioned into groups of size W, each group being W consecutive integers....
High-Level Design
If len(tickets) % W != 0, return False. Otherwise count each number. Process the distinct numbers in ascending order. The smallest number with a non-zero count, call it x, cannot be in the middle of...