Stripe Coding Interview: Order Shipping Cost

Based on questions reported for Stripe interviews

The interviewer opens

Hi, and thanks for joining. Welcome to your interview for the software engineer role at Stripe. We'll work through a coding problem together, so please think out loud as you code. You can pause the interview any time with the Pause button at the top right of your screen.

The problem is about working out an order's shipping cost from a table of rates, which is the kind of pricing logic payments systems deal with a lot. It's in the Problem tab on the right, so please read it through and ask me any questions before you start.

The problem

Compute an order's total shipping cost from a per-country, per-product rate table.

  • country: the destination country code, e.g. "US".
  • items: the order lines, each {product, quantity}.
  • rates: rates[country][product] is the shipping cost in cents for one unit of that product to that country.

Each line costs quantity times its per-unit rate; return the sum over all lines in cents. Every country and product in the order is present in rates, each product appears at most once in items, and quantities are non-negative.

Example: country = "US", items = [{product: "mouse", quantity: 20}, {product: "laptop", quantity: 5}], rates = {"US": {"mouse": 550, "laptop": 1000}, "CA": {"mouse": 750, "laptop": 1100}} → 16000

Up to 10^4 items and 200 countries.