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.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

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
Greedy
Hash Map
Sorting
Counting
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample Answer
Requirements
  • Input: list tickets of integers (duplicates allowed) and integer W >= 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...


Submit Your Answer
Markdown supported