Compute the Best Active Brand Promotion Timeline Across Overlapping Campaigns
Last updated: November 29, 2026
Quick Overview
A brand can run many overlapping wholesale promotions, each with a start day, an exclusive end day, a discount percent and an id. Return the timeline as maximal non-overlapping segments (start, end, percent, promo_id) showing which promotion gives the retailer the best discount at every moment, skipping gaps with no active promotion.
Faire
November 29, 20260
0
0 solved
A brand can run many overlapping wholesale promotions, each with a start day, an exclusive end day, a discount percent and an id. Return the timeline as maximal non-overlapping segments (start, end, percent, promo_id) showing which promotion gives the retailer the best discount at every moment, skipping gaps with no active promotion.
Brands on a wholesale marketplace stack event discounts, first-order offers and seasonal promotions, and the retailer should always see the single best one applied. The interviewer is checking a sweep line with a max-heap and lazy deletion, merging of adjacent equal segments, and deterministic tie-breaking.
What the Interviewer Expects
- Build a sorted set of boundary points from starts and ends
- Sweep boundaries, pushing newly started promos into a max-heap
- Lazily pop expired promos from the top of the heap
- Emit a segment per interval and merge adjacent identical ones
- Define a deterministic tie-break for equal discounts
- State O(n log n) complexity
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
- How would you support a query 'best discount on day d' in O(log n) after preprocessing?
- What changes if promotions can stack multiplicatively up to a cap?
- How would you handle a promotion being cancelled mid-flight in a streaming setting?
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 of (start, end, pct, promo_id) with end exclusive. Output: sorted segments covering exactly the times when at least one promotion is active, each labelled with the winning promotion. Tie-b...
High-Level Design
The winner can only change at a boundary, so sort all starts and ends into a list of distinct points. Between consecutive points the active set is fixed. Sweep the points; at each point, add promos th...