Apply the Best Store and Platform Coupons to a Cart
Last updated: November 29, 2026
Quick Overview
Given a cart of items from several stores and a list of threshold coupons (spend X, get Y off) scoped either to one store or to the whole platform, choose at most one coupon per store plus one platform coupon to minimize the final total. All thresholds are checked against pre-discount subtotals.
Temu
November 29, 20260
0
0 solved
Given a cart of items from several stores and a list of threshold coupons (spend X, get Y off) scoped either to one store or to the whole platform, choose at most one coupon per store plus one platform coupon to minimize the final total. All thresholds are checked against pre-discount subtotals.
Threshold coupons are everywhere in Temu's checkout, so a phone screen often opens with a small promotion-engine warm-up. The interviewer checks clean grouping by key, careful money handling in integer cents, and whether you notice when the stacking rules make greedy choices safe or unsafe.
What the Interviewer Expects
- Ask how coupons stack and which subtotal each threshold uses
- Use integer cents, never floats, for money
- Group items by store in one pass
- Pick the best eligible coupon per scope with a clear tie-break
- Clamp the final total at zero
- Explain why independent scopes make the greedy choice optimal
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 changes if the platform threshold is checked after store discounts are applied?
- How would you support coupons that only apply to certain categories inside a store?
- How do you make the result explainable to the user on the checkout page?
- How would you handle percentage-off coupons with a cap?
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: items as (store_id, price_cents) and coupons as (scope, threshold_cents, off_cents) where scope is a store id or PLATFORM. Each store may use at most one of its coupons; one platform ...
High-Level Design
Because every threshold is measured on the pre-discount subtotal, the choice for each scope is independent: picking a coupon for store A cannot make any other coupon ineligible. So the optimum is simp...