[ OK ]2a15f417-c9bb-4ab2-b606-24568b9f30c7 — full content available
[ INFO ]category: Coding difficulty: unknown freq: first seen: 2026-01-17
[UNKNOWN][CODING]High Frequency
$catproblem.md
Hey r/DarkInterview — sharing a free Stripe coding question from https://darkinterview.com .
Shipping Cost Calculator
Design a shipping cost engine for an e-commerce platform where pricing depends on country, product, and quantity-based pricing rules.
The problem progresses from simple fixed pricing to tiered and mixed pricing models, similar to real-world logistics/payment infra tradeoffs.
Part 1: Fixed Rate Shipping
Implement calculate_shipping_cost(order, shipping_cost) where each product has a fixed per-unit shipping cost by country.
Compact example (US + CA):
US: mouse(20*550) + laptop(5*1000) = 16000
CA: mouse(20*750) + laptop(5*1100) = 20500
Part 2: Tiered Incremental Pricing
Now each product has quantity tiers with {minQuantity, maxQuantity, cost}.
You must split quantity across tiers and sum tier-by-tier costs.
Compact example (laptop qty=5):
US tiers: 0-2 @1000, 3+ @900
Cost: (2*1000) + (3*900) = 4700
Total order: 15700
CA tiers: 0-2 @1100, 3+ @1000
Cost: (2*1100) + (3*1000) = 5200
Total order: 20200
Part 3: Mixed Pricing Models (fixed + incremental)
Support tier type:
incremental: per-unit (units * cost)
fixed: flat fee once that tier is used
Compact example (laptop qty=5):
US: fixed 1000 for first tier + (3*900) = 3700
Total order: 14700
CA: fixed 1100 for first tier + (3*1000) = 4100
Total order: 19100
Edge Cases (Important)
Missing country or product config: error vs skip vs default?