Design Underground System Problem

Design Underground System Problem — ExecCode Medium DSA Practice

Solve the Design Underground System problem on ExecCode. Free online medium DSA practice in Hashing. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description An underground railway system is keeping track of customer travel times between different stations. They are using this data to calculate the average time it takes to travel from one station to another. Implement the UndergroundSystem class: void checkIn(int id, string stationName, int t) A customer with a card ID equal to id, checks in at the station stationName at time t. A customer can only be checked into one place at a time. void checkOut(int id, string stationName, int t) A customer with a card ID equal to id, checks out from the station stationName at time t. double getAverageTime(string startStation, string endStation) Returns the average time it takes to travel from startStation to endStation. The average time is computed from all the previous traveling times from startStation to endStation that happened directly, meaning a check in at startStation followed by a check out from endStation. The time it takes to travel from startStation to endStation may be different from the time it takes to travel from endStation to startStation. There will be at least one customer that has traveled from startStation to endStation before getAverageTime is called. You may assume…

Examples

Input {"data": "checkIn 45 Leyton 3\ncheckIn 32 Paradise 8\ncheckIn 27 Leyton 10\ncheckOut 45 Waterloo 15\ncheckOut 27 Waterloo 20\ncheckOut 32 Cambridge 22\ngetAverageTime Leyton Waterloo\ngetAverageTime Paradise Cambridge\ngetAverageTime Leyton Waterloo"}; Output 11.00000 14.00000 11.00000. Input {"data": "checkIn(45,\"Leyton\",3); checkOut(45,\"Waterloo\",15); getAverageTime(\"Leyton\",\"Waterloo\")"}; Output 12.00000. Input {"data": "checkIn(10,\"A\",3); checkOut(10,\"B\",13); getAverageTime(\"A\",\"B\")"}; Output 10.00000

Constraints

1 <= id, t <= 10^6 1 <= stationName.length, startStation.length, endStation.length <= 10 All strings consist of uppercase and lowercase English letters and digits. There will be at most 2 * 10^4 calls in total to checkIn, checkOut, and getAverageTime. Answers within 10^-5 of the actual value will be accepted.

Practice Design Underground System free on ExecCode. Browse DSA problems, topic map, and placement guides.