InterviewDB
Question
Coupon System - Apply and Stack Discount Coupons on an Order
phone
Question Details
Problem
Design a coupon application system for an e-commerce checkout. Coupons have types: percent_off, fixed_off, buy_x_get_y_free, and category_discount. Rules:
- At most 2 coupons can be applied per order.
- Coupons cannot reduce the price below $0.
- Some coupons are exclusive (cannot stack with others).
Implement:
- apply_coupons(order, coupon_codes) -> CheckoutResult
python
class CouponSystem:
def apply_coupons(
self,
order: dict, # {"items": [{"id", "category", "price", "qty"}]}
coupon_codes: List[str]
) -> dict: # {"original": float, "discount": float, "final": float, "applied": List[str]}
...
Example:
order = {"items": [{"id":"i1","category":"electronics","price":200,"qty":1}]}
coupons = ["SAVE10PCT", "TECH20"]
# SAVE10PCT: 10% off entire order
# TECH20: $20 off electronics category
apply_coupons(order, coupons) ->
{"original": 200, "discount": 40.0, "final": 160.0, "applied": ["SAVE10PCT","TECH20"]}
Follow-ups
- How do you determine the optimal order to apply coupons to maximize the discount?
- How do you enforce the exclusivity constraint when 3+ coupons are submitted?
- How would you validate coupon expiry and single-use restrictions?
- How do you handle a
buy_x_get_y_freecoupon across multiple cart items?
Full Details
Problem
Design a coupon application system for an e-commerce checkout. Coupons have types: percent_off, fixed_off, buy_x_get_y_free, and category_discount. Rules:
- At most 2 coupons can be applied per order.
- Coupons cannot reduce the price below $0.
- Some coupons are exclusive (cannot stack with others).
Implement:
- apply_coupons(order, coupon_codes) -> CheckoutResult
python
class CouponSystem:
def apply_coupons(
self,
order: dict, # {"items": [{"id", "category", "price", "qty"}]}
coupon_codes: List[str]
) -> dict: # {"original": float, "discount": float, "final": float, "applied": List[str]}
...
Example:
order = {"items": [{"id":"i1","category":"electronics","price":200,"qty":1}]}
coupons = ["SAVE10PCT", "TECH20"]
# SAVE10PCT: 10% off entire order
# TECH20: $20 off electronics category
apply_coupons(order, coupons) ->
{"original": 200, "discount": 40.0, "final": 160.0, "applied": ["SAVE10PCT","TECH20"]}
Follow-ups
- How do you determine the optimal order to apply coupons to maximize the discount?
- How do you enforce the exclusivity constraint when 3+ coupons are submitted?
- How would you validate coupon expiry and single-use restrictions?
- How do you handle a
buy_x_get_y_freecoupon across multiple cart items?
Free preview. Unlock all Plaid questions →
About This Question
This is a reported interview question from a plaid interview during the phone round.
It covers the following topics: Coding, Phone, Onsite, Stack .
More Plaid Interview Questions
1p3a
plaid fulltime machine learning engineer technical phone screen interview
InterviewDB
Bank ID Resolution - Resolve Merged Bank Account Identifiers
InterviewDB
Healthy Data - Detect and Handle Data Quality Issues in ML Pipelines
InterviewDB
Plaid SWE Phone - Group Transactions
InterviewDB
Payment Schedule - Generate Amortization Schedule for a Loan