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
Coding & Algorithms
Software Engineer
Faire
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

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
sweep line
heap with lazy deletion
interval merging
tie-breaking
promotions
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
  • 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 Problems
Sample 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...


Submit Your Answer
Markdown supported

Related Questions