Compute Price Adjustment Refunds Over a Forward Window

Last updated: November 29, 2026

Quick Overview

Given an item's daily listed price and a list of orders (order id, purchase day, price paid), compute each order's price adjustment refund: the amount paid minus the lowest listed price during the next D days, or zero if the price never dropped.

Temu
Coding & Algorithms
Software Engineer
Temu
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Medium

0

0

0 solved


Given an item's daily listed price and a list of orders (order id, purchase day, price paid), compute each order's price adjustment refund: the amount paid minus the lowest listed price during the next D days, or zero if the price never dropped.

Temu offers price adjustments when an item gets cheaper shortly after purchase, which at its order volume becomes a batch job over price histories. The interviewer wants to see you move from an O(N times D) scan to a monotonic deque and prove it against a brute force.

What the Interviewer Expects
  • Pin down the window (days d+1 through d+D, clipped at the history end)
  • Start with the brute force and state its cost
  • Precompute a forward sliding minimum with a monotonic deque
  • Answer each order in O(1) after preprocessing
  • Validate against brute force on random inputs
Key Topics to Cover
monotonic deque
sliding window minimum
batch processing
pricing
testing against brute force
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 do you handle per-SKU histories when there are hundreds of millions of orders?
  • What if refunds should use the lowest price only if it lasted at least one hour?
  • How would you answer arbitrary window lengths per order? (sparse table or segment tree)
  • How do you stop a seller from briefly dropping a price to trigger mass refunds?
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

prices[d] is the listed price on day d. For order (id, d, paid) the refund is max(0, paid - min(prices[d+1 .. d+D])), and zero if that range is empty. Many orders can share a day, so we want a p...

High-Level Design

Brute force scans D days per order: O(Q times D). Instead compute future_min[d] for every day using a sliding window minimum moving right to left. The deque stores day indices with increasing prices...


Submit Your Answer
Markdown supported

Related Questions