Which Discounts Stack?

Hard ⏱ 18 min 30% acceptance ★★★★★ 4.8
Write best_price(price, coupons) where each coupon is (code, pct, stackable). Rules: at most ONE non-stackable coupon may be used, but any number of stackable ones; stackable coupons apply sequentially (compounding, not summed). Choose whichever combination — best non-stackable alone, all stackables together, or best non-stackable plus all stackables — yields the lowest price. Return it rounded to 2 decimals.

Examples

Example 1
Input
best_price(1000, [('A', 20, False), ('B', 10, True), ('C', 5, True)])
Output
684.0
Explanation

20% then 10% then 5% compound: 1000×0.8×0.9×0.95.

Constraints

  • Sequential compounding for stackables.
  • Consider the no-coupon case too (empty list).

Topics

Business Logicpromotion rules

Companies

MyntraAjioNykaa

Hints

Hint 1

Stacked factor: product of (1 - pct/100).

Hint 2

Best non-stackable is simply the max pct.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.