Shipping Cost Calculator Part 1 - Fixed Per-Unit Price
Updated
Problem 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 Phone Screen questions
- Merchant Payout Scheduler, Part 2: Per-Merchant SchedulesPHONE SCREEN · Seen Nov 2026
- Financial Account LedgerOA · PHONE SCREEN · Seen Nov 2026
- Business Account KYC Verification — Parts 1–5PHONE SCREEN · Seen Nov 2026
- Render a Task Tree from CSV RowsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Invoice / Payment ReconciliationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Linked Merchants Within Two HopsPHONE SCREEN · Seen Nov 2026
- Portfolio Valuation, Part 1PHONE SCREEN · Seen Nov 2026
- Account Roles With Parent-User InheritancePHONE SCREEN · Seen Nov 2026
- Merchant Payout Scheduler, Part 3: Hold PeriodsPHONE SCREEN · Seen Nov 2026
- Merchant Payout Scheduler, Part 1PHONE SCREEN · Seen Nov 2026
Similar questions at other companies
- SimpleRDD Word CountDatologyAI · PHONE SCREEN
- Project JSON Fields into a Target FormatBooking.com · PHONE SCREEN
- Count Complete Toll JourneysOnePay · PHONE SCREENOnePay interview questions
- Wordle Feedback with Duplicate LettersScale AI · PHONE SCREENScale AI interview questions
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- File Storage ServiceCresta · PHONE SCREENCresta interview questions
- String Interpolation with a Missing-Value ModeMongoDB · PHONE SCREENMongoDB interview questions
- Dasher Pay with Store Waits and Peak HoursDoorDash · PHONE SCREENDoorDash interview questions
- Return Every Matching DecryptionDuolingo · PHONE SCREENDuolingo interview questions
- Fixed-Order Task Run Time With CooldownWaymo · PHONE SCREENWaymo interview questions