Apply volume discounts, category surcharges and a minimum-order fee to marketplace orders

Quick Overview

Price a list of marketplace orders by applying a tiered volume discount, a category surcharge and a minimum-order fee, then rounding each cost to cents. It tests rule ordering, picking the right tier and exact money arithmetic in a single linear pass.

Apply volume discounts, category surcharges and a minimum-order fee to marketplace orders

Company: Uber

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

You are given a list of `orders` in a marketplace. Each order is represented as `[category, quantity, base_price]`, where `category` is a string, `quantity` is an integer, and `base_price` is the price per unit. Compute the final cost of each order by applying these pricing rules in order: 1. Apply a volume discount to the raw cost (`quantity * base_price`): 30% off if `quantity >= 100`, otherwise 20% off if `quantity >= 50`, otherwise 10% off if `quantity >= 10`, otherwise no discount. 2. After the discount, apply a surcharge based on the category: `"electronics"` adds 15%, `"perishable"` adds 20%, and `"luxury"` adds 25%. All other categories have no surcharge. 3. If the cost after the discount and surcharge is below `50.0`, add a flat fee of `10.0` (the minimum order threshold). Return a list of the final costs for each order, each rounded to 2 decimal places. ### Function Signature ```python def simulate_marketplace(orders: list[list]) -> list[float]: ``` ### Rules - Only one volume tier applies, the highest one the quantity reaches. Discounts do not stack. - Treat each `base_price` as the exact decimal number written in the input (`0.1` is one tenth) and compute every cost exactly. - The threshold test uses the unrounded cost. A cost of exactly `50.0` gets no fee. - Round once, at the end, to 2 decimal places. An exact half cent rounds up, so `58.125` becomes `58.13`. - Return the costs as floats, in the same order as `orders`. ### Constraints - `1 <= len(orders) <= 10^4` - Each order is `[category, quantity, base_price]` - `category` is a non-empty lowercase string - `1 <= quantity <= 10^4` - `0.01 <= base_price <= 10000.00` ### Examples ```text Input: orders = [["electronics",25,10],["perishable",5,8],["books",100,3]] Output: [258.75, 58.0, 210.0] ``` The first order costs 250.0 raw, 225.0 after the 10% discount and 258.75 after the 15% electronics surcharge. The second rises from 40.0 to 48.0 with the perishable surcharge and gets the 10.0 fee for being under 50, and the third gets 30% off 300.0 with no surcharge. ```text Input: orders = [["luxury",1,20],["general",50,2],["electronics",100,5]] Output: [35.0, 80.0, 402.5] ``` The luxury order goes from 20.0 to 25.0 with its surcharge and then picks up the fee. The general order gets 20% off 100.0, and the electronics order gets 30% off 500.0 (350.0) plus 15%, which gives 402.5. ```text Input: orders = [["luxury",3,15.5],["general",10,5]] Output: [58.13, 55.0] ``` The luxury order is exactly 58.125 (46.5 plus 25%), and the half cent rounds up to 58.13. The general order reaches the 10% tier at exactly 10 units, so 50.0 becomes 45.0, which is below 50 and gets the fee.

Overview: Price a list of marketplace orders by applying a tiered volume discount, a category surcharge and a minimum-order fee, then rounding each cost to cents. It tests rule ordering, picking the right tier and exact money arithmetic in a single linear pass.

Uber logo
Uber
Nov 24, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

You are given a list of orders in a marketplace. Each order is represented as [category, quantity, base_price], where category is a string, quantity is an integer, and base_price is the price per unit.

Compute the final cost of each order by applying these pricing rules in order:

  1. Apply a volume discount to the raw cost ( quantity * base_price ): 30% off if quantity >= 100 , otherwise 20% off if quantity >= 50 , otherwise 10% off if quantity >= 10 , otherwise no discount.
  2. After the discount, apply a surcharge based on the category: "electronics" adds 15%, "perishable" adds 20%, and "luxury" adds 25%. All other categories have no surcharge.
  3. If the cost after the discount and surcharge is below 50.0 , add a flat fee of 10.0 (the minimum order threshold).

Return a list of the final costs for each order, each rounded to 2 decimal places.

Function Signature

def simulate_marketplace(orders: list[list]) -> list[float]:

Rules

  • Only one volume tier applies, the highest one the quantity reaches. Discounts do not stack.
  • Treat each base_price as the exact decimal number written in the input ( 0.1 is one tenth) and compute every cost exactly.
  • The threshold test uses the unrounded cost. A cost of exactly 50.0 gets no fee.
  • Round once, at the end, to 2 decimal places. An exact half cent rounds up, so 58.125 becomes 58.13 .
  • Return the costs as floats, in the same order as orders .

Constraints

  • 1 <= len(orders) <= 10^4
  • Each order is [category, quantity, base_price]
  • category is a non-empty lowercase string
  • 1 <= quantity <= 10^4
  • 0.01 <= base_price <= 10000.00

Examples

Input: orders = [["electronics",25,10],["perishable",5,8],["books",100,3]]
Output: [258.75, 58.0, 210.0]

The first order costs 250.0 raw, 225.0 after the 10% discount and 258.75 after the 15% electronics surcharge. The second rises from 40.0 to 48.0 with the perishable surcharge and gets the 10.0 fee for being under 50, and the third gets 30% off 300.0 with no surcharge.

Input: orders = [["luxury",1,20],["general",50,2],["electronics",100,5]]
Output: [35.0, 80.0, 402.5]

The luxury order goes from 20.0 to 25.0 with its surcharge and then picks up the fee. The general order gets 20% off 100.0, and the electronics order gets 30% off 500.0 (350.0) plus 15%, which gives 402.5.

Input: orders = [["luxury",3,15.5],["general",10,5]]
Output: [58.13, 55.0]

The luxury order is exactly 58.125 (46.5 plus 25%), and the half cent rounds up to 58.13. The general order reaches the 10% tier at exactly 10 units, so 50.0 becomes 45.0, which is below 50 and gets the fee.