Stripe Coding Interview Question: Shipping Routes Through at Most One Intermediate Country

20 Views
No Comments

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 asks you to compute a shipping route between two countries with at most one intermediate country. The result must include the full route, the transport methods used on each leg, and the total cost. A natural approach is to model countries as nodes and shipping options as weighted edges, then compare the direct path with all two-leg paths through one possible middle country, selecting the cheapest valid route and formatting the answer accordingly.

END
 0