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
Coding & Algorithms
Software Engineer
Temu
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

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
hash maps
greedy selection
promotion rules
money in cents
edge cases
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 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 Problems
Sample 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...


Submit Your Answer
Markdown supported

Related Questions