Build the Effective Price Timeline From Overlapping Promotions
Last updated: November 29, 2026
Quick Overview
Given a product's base price and a list of promotions, each a half-open time window with a promo price, return the merged timeline of effective prices over a horizon, where the effective price at any moment is the lowest of the base price and all active promotions.
Fanatics
November 29, 20260
0
0 solved
Given a product's base price and a list of promotions, each a half-open time window with a promo price, return the merged timeline of effective prices over a horizon, where the effective price at any moment is the lowest of the base price and all active promotions.
Fanatics runs stacked campaigns around Black Friday, the draft and championship weeks, and the pricing service has to answer "what will this jersey cost at time t" for previews, price-history compliance and ads feeds. The interviewer checks interval sweep reasoning and careful boundary handling.
What the Interviewer Expects
- Collect all boundary points and sweep between them
- Use a min-heap keyed on price with lazy removal of expired promos
- Respect half-open intervals so adjacent windows do not double count
- Merge adjacent segments with the same price
- Clip promotions to the requested horizon
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
- Promotions now have priorities, and a higher priority promo wins even if it is pricier. What changes?
- How would you answer point queries in O(log n) after preprocessing?
- Some promos are percent-off of the current price rather than fixed prices. How do you compose them?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Times are integers (epoch minutes), intervals are [start, end). Output a list of (start, end, price) covering [horizon_start, horizon_end) with no gaps and no two adjacent segments at the same p...
High-Level Design
Effective price only changes at promo boundaries. Sort the distinct boundary times, and for each elementary segment push promos that have started onto a min-heap of (price, end). Pop heap tops whose...