Design Underground System

Medium · Hashing · about 20 minutes

Asked at Bloomberg, Amazon, Uber, Google, Microsoft.

Track customer travel times between subway stations to report average trip times.

  • checkIn(id, stationName, t): customer id enters at stationName at time t.
  • checkOut(id, stationName, t): customer id leaves at stationName at time t.
  • getAverageTime(startStation, endStation): the average time of all completed trips directly from

startStation to endStation (at least one exists). Answers within 10⁻⁵ are accepted.

A customer is checked into at most one station at a time, and check-outs always follow check-ins.

Related guides