Pick the Best Single Coupon for a Mixed Category Cart
Last updated: November 29, 2026
Quick Overview
Given a cart of items (category, unit price in won, quantity) and a list of coupons that are either percentage or flat amount, scoped to one category or the whole cart, with minimum spend and optional discount caps, return the lowest payable total when at most one coupon may be applied, and which coupon achieves it.
Coupang
November 29, 20260
0
0 solved
Given a cart of items (category, unit price in won, quantity) and a list of coupons that are either percentage or flat amount, scoped to one category or the whole cart, with minimum spend and optional discount caps, return the lowest payable total when at most one coupon may be applied, and which coupon achieves it.
Coupons and instant discounts are everywhere on Coupang's checkout, and the rules (category scope, minimum spend, caps) are a classic source of off-by-one and rounding bugs. A phone screen uses this to check that you can turn messy business rules into clean, well-tested code quickly.
What the Interviewer Expects
- Clarify scope rules: does minimum spend apply to the eligible subtotal or the whole cart
- Precompute per-category subtotals once instead of rescanning items per coupon
- Use integer won arithmetic and state the rounding rule for percentage discounts
- Never let a discount exceed the eligible amount
- Deterministic tie-break between coupons with equal discount
- Talk through tests: no eligible coupon, cap binding, flat coupon larger than subtotal
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
- How would you change this if one cart-wide coupon and one category coupon could stack?
- What if coupons have per-user usage limits stored in another service?
- How would you explain to the customer why a coupon was not applied?
- How does this change when shipping fee waivers are also coupons?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Inputs: items as (sku, category, unit_price, qty) and coupons with id, category (or None for the whole cart), kind (pct or flat), value, min_spend, and for percentage coupons an opti...
High-Level Design
One pass over items builds the cart subtotal and a dictionary of category subtotals. Then each coupon is evaluated in O(1): find its eligible amount, check minimum spend, compute the discount, clamp i...