Filter Ticket Listings by Seller Split Rules for a Buyer Quantity
Last updated: November 29, 2026
Quick Overview
Each listing has a price, a quantity and a seller split rule (ANY, PAIRS, NO_SINGLE, or ALL). Given a buyer's requested quantity q, return the ids of listings that can legally sell exactly q tickets, sorted by price and then id.
StubHub
November 29, 20260
0
0 solved
Each listing has a price, a quantity and a seller split rule (ANY, PAIRS, NO_SINGLE, or ALL). Given a buyer's requested quantity q, return the ids of listings that can legally sell exactly q tickets, sorted by price and then id.
On StubHub the first thing a buyer picks is how many tickets they want, and the listing grid must hide listings the seller would not split that way (for example, a seller who refuses to be left holding one orphan ticket). It is a warm-up that checks careful reading of business rules and clean modeling, not tricky algorithms.
What the Interviewer Expects
- Restates each split rule precisely before coding, including what PAIRS means
- Encodes the rules in one small predicate rather than scattered conditionals
- Rejects any q larger than the listed quantity first
- Sorts by price with a stable, deterministic tie-break
- Mentions unknown rules and how they should default
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
- A seller wants 'any split as long as the remainder is a multiple of 2'. How would you generalise the rule model?
- How would you precompute, per listing, the set of valid quantities so the filter becomes a lookup?
- The grid shows 'price per ticket including fees'. Where would you compute that?
- How would you test this predicate so a future rule does not silently break the others?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Rules, for a listing of n tickets and request q:
- ANY: any q from 1 to n.
- PAIRS: q must be even (the seller sells in pairs).
- NO_SINGLE: the remainder
n - qmust not be exactly 1, so the seller ...
High-Level Design
Write a pure function can_serve(n, rule, q) and apply it as a filter, then sort. Keeping the rule logic in one function makes it testable in isolation and easy to extend with a table of rule handler...