Problem · Hash Table
Shipping Cost Calculator Part 1 - Fixed Per-Unit Price
Learn this problemProblem statement
Calculate the total shipping cost for an online order. The cost depends on the destination country and the product, and in this first version every product has a single fixed cost per unit.
Inputs:
country: the destination country code for the order.items: aString[]where each entry is"product,quantity".rules: aString[]where each entry is"country,product,cost"giving the fixed per-unit cost of a product in a country.
For each ordered item, multiply its quantity by the per-unit cost for that product in the order's country, and sum across all items. Return the total as an integer.
Function
calculateShippingCost(country: String, items: String[], rules: String[]) → intExamples
Example 1
country = "US"items = ["mouse,20", "laptop,5"]rules = ["US,mouse,550", "US,laptop,1000", "CA,mouse,750", "CA,laptop,1100"]return = 16000Using US rates: mouse 20 x 550 = 11000, laptop 5 x 1000 = 5000. Total = 16000.
Example 2
country = "CA"items = ["mouse,20", "laptop,5"]rules = ["US,mouse,550", "US,laptop,1000", "CA,mouse,750", "CA,laptop,1100"]return = 20500Using CA rates: mouse 20 x 750 = 15000, laptop 5 x 1100 = 5500. Total = 20500.
Constraints
itemsentries are"product,quantity"with integer quantity.rulesentries are"country,product,cost"with integer cost (per unit).- Use the per-unit cost for the order's country and each product.
- Total = sum over items of
quantity * cost; return as an integer.
More Stripe problems
- Group Linked Merchant RecordsPHONE SCREEN · Seen Jul 2026
- Invoice / Payment ReconciliationPHONE SCREEN · Seen Jul 2026
- Incident MonitorOA · Seen Jul 2026
- Merchant Fraud Risk ScoringOA · Seen Jul 2026
- WebSocket Load Balancer — Basic Load Balancing (Part 1)OA · Seen Jul 2026
- Rule-Driven Transaction Fraud DetectionOA · PHONE SCREEN · Seen Jul 2026
- Deployment Window SchedulerOA · Seen Jul 2026
- Directly Linked UsersOA · Seen Jun 2026