Stripe OA Interview Question: Sending Terminal Hardware

20 Views
No Comments

Sending Terminal Hardware (Part 1)

Stripe operates in many countries and sends out payment terminal hardware through different shipping methods based on routes between countries.

Your task is to write a program that determines the cost of shipping for available methods and routes.

An example input string looks like this:

inputString = "US:UK:FedEx:5, UK:US:UPS:4, UK:CA:FedEx:7, US:CA:DHL:10, UK:FR:DHL:2"

Each entry represents a source country, target country, shipping method, and a shipping cost. For instance, shipping via FedEx from the US to the UK costs $5 per unit.

Your program will read and parse that input string.

Write a function shippingCost(inputString, sourceCountry, targetCountry, method) that can look up the cost of shipping via a specified method from the source country to the target country from the input list.

For example:

shippingCost(inputString, "US", "UK", "FedEx") should return 5
shippingCost(inputString, "UK", "FR", "DHL") should return 2

Sending Terminal Hardware (Part 2)

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 parse a compact shipping-route string and answer two kinds of queries. In Part 1, you directly look up the shipping cost for a given source country, target country, and method. In Part 2, you extend the solution to search for routes with at most one intermediate country, then return the full route, the methods used, and the total cost. A practical solution uses hash maps to index routes by source and destination, making direct lookups fast and allowing efficient checking of one-stop paths.

END
 0