Friendly reminder: If you haven’t read the previous article “Shipping Cost Calculation,” it is recommended to read it first, as this question is actually a continuation of the logic from that article. Link to the previous article
🧾 Problem Description
Modify your program such that it can find shipping routes through at most one intermediate country. Any shipping methods are allowed. Output the route, the method(s) taken, and the total cost. For instance
shippingRoute(inputString, "US", "FR")
should return
{route: "US -> UK -> FR",
method: "FedEx -> DHL",
cost: 7
This problem is an extension of the previous question on “calculating transportation costs directly from one country to another.” Now, you not only need to calculate the cost but also consider that transportation may pass through one intermediate country (at most one) and may use multiple transportation methods. Ultimately, you need to output three pieces of information:
In other words, you need to find a route between the “starting country” and the “destination country”: either directly or via one intermediate country. For each possible route, there are transportation methods and corresponding costs. You need to find the optimal route (usually meaning the least expensive) and format the output.
Interviewer follow-up questions
Summary
This problem continues the “transportation cost calculation” theme from the previous question but increases the difficulty by adding path selection, multiple methods, and an intermediate transfer mechanism, making it closer to real-world logistics/payment system design problems. Candidates should demonstrate the ability to:
If you want to systematically improve your skills in “system design + algorithms + real business scenarios,” especially for companies like Stripe, Meta, and Amazon that frequently ask such questions, our Stripe mock interview coaching is the perfect help: