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
Software Engineering Fundamentals
Software Engineer
Meesho
November 29, 2026
Software Engineer
Onsite
Software Engineering Fundamentals
Medium

0

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
object-oriented design
machine coding
money handling
rule engines
extensibility
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. 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 Problems
Sample 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
  • Coupon owns is_valid(cart) and discount(cart, already_taken), so a new type only overrides these.
  • CouponEngine.best_discount builds candidate options: one stacked option of all stackable c...

Submit Your Answer
Markdown supported

Related Questions