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

0

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
sweep line
difference events
offline queries
sorting
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
  • 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 Problems
Sample Answer
Requirements
  • Input: promos list of (start, end, amount) with half-open intervals, queries list of timestamps.
  • Output: list where ans[i] is the sum of amounts of promos with start <= 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...


Submit Your Answer
Markdown supported