Problem
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 theUndergroundSystem class:
UndergroundSystem()Initializes the object of the underground system.void checkIn(int id, string stationName, int t)A customer with a card ID equal toid, checks in at the stationstationNameat timet. 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 toid, checks out from the stationstationNameat timet.double getAverageTime(string startStation, string endStation)Returns the average time it takes to travel fromstartStationtoendStation. The average time is computed from all the previous traveling times fromstartStationtoendStationthat happened directly, meaning a check in atstartStationfollowed by a check out fromendStation. The time it takes to travel fromstartStationtoendStationmay be different from the time it takes to travel fromendStationtostartStation. There will be at least one customer that has traveled fromstartStationtoendStationbeforegetAverageTimeis called.
checkIn and checkOut methods are consistent. If a customer checks in at time t1 then checks out at time t2, then t1 < t2. All events happen in chronological order.
Examples
Constraints
1 <= id, t <= 10^61 <= 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^4calls in total tocheckIn,checkOut, andgetAverageTime. - Answers within
10^-5of the actual value will be accepted.