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): customeridenters atstationNameat timet.checkOut(id, stationName, t): customeridleaves atstationNameat timet.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.