Machine Coding A Stackable Coupon Engine For Cart Checkout
Last updated: November 29, 2026
Quick Overview
Implement a coupon engine that takes a cart and a list of coupon codes (flat or percent, with minimum cart value, optional category restriction, optional cap, and a stackable flag) and returns the best achievable discount and which coupons produce it, where non-stackable coupons apply alone and stackable ones combine.
Meesho
November 29, 20260
0
0 solved
Implement a coupon engine that takes a cart and a list of coupon codes (flat or percent, with minimum cart value, optional category restriction, optional cap, and a stackable flag) and returns the best achievable discount and which coupons produce it, where non-stackable coupons apply alone and stackable ones combine.
Meesho runs constant sales, new-user offers and category coupons, and a machine coding round in this style asks for working, extensible object-oriented code in about 90 minutes. The interviewer looks for clean domain modelling, correct money handling, and an ordering rule that prevents discounts from exceeding the eligible amount.
What the Interviewer Expects
- Models money in integer paise, never floats
- Separates validity checks from discount computation
- Applies percent coupons before flat ones when stacking and justifies it
- Never lets discounts exceed the eligible subtotal
- Compares the stacked option with each standalone coupon and picks the best
- Leaves room for new coupon types without editing the engine
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- How would you add a buy two get one free coupon type?
- How would you enforce a per-user usage limit under concurrent checkouts?
- Finance wants discounts split per line item for returns. How does the model change?
- How would you test this engine?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
Cart: items with sku, category, price (paise), qty. Coupon: FLAT (value in paise) or PERCENT (value in percent), min_cart, optional cap, optional category, stackable. Rules: invalid or u...
High-Level Design
Couponownsis_valid(cart)anddiscount(cart, already_taken), so a new type only overrides these.CouponEngine.best_discountbuilds candidate options: one stacked option of all stackable c...