Total Promo Discount Active at Each Rider Query Time
Last updated: November 29, 2026
Quick Overview
Promotions are intervals [start, end) each carrying a discount amount, and overlapping promotions stack; given many query timestamps, return the total discount active at each query time.
Uber
November 29, 20260
0
0 solved
Promotions are intervals [start, end) each carrying a discount amount, and overlapping promotions stack; given many query timestamps, return the total discount active at each query time.
Uber's pricing and promotions stack in complicated ways, and reconciling what a rider should have been offered at a given moment is a real backfill task. The interviewer checks that you avoid O(P x Q) scanning by sweeping over sorted events and sorted queries together.
What the Interviewer Expects
- Convert each promo into a +amount event at start and -amount at end
- Sort events and queries, then sweep once
- Process end events before queries at the same timestamp (half-open)
- Return answers in the original query order
- Mention a Fenwick tree or prefix array for online queries
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
- What if queries arrive online, interleaved with new promotions?
- What if a rider can use at most the single largest active promo instead of stacking?
- How would you cap the stacked discount at a maximum per trip?
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:
promoslist of(start, end, amount)with half-open intervals,querieslist of timestamps. - Output: list where
ans[i]is the sum of amounts of promos withstart <= queries[i] < end....
High-Level Design
Brute force checks every promo for every query: O(P x Q). Instead build events: (start, +amount) and (end, -amount). Sort events by time. Sort query indices by time. Sweep: before answering a quer...