Underground Tunnel
Implement a data structure with the following methods:
void checkIn(int userId, String station, int timestamp)which means useruserIdchecked in to stationstationat timetimestamp. A user can only be checked in at one station at a time.void checkOut(int userId, String station, int timestamp)which means useruserIdchecked out of stationstationat timetimestamp.float averageTime(String start, String end)returns the average time for a person to move between stationstartandend.
You can assume that for a given user, checkIn always occurs before checkOut. Also, averageTime will only be called if at least one person travelled between the two stations.
Constraints
0 ≤ n ≤ 100,000wherenis the number of calls tocheckIn,checkOutandaverageTime.
https://binarysearch.com/problems/Underground-Tunnel
Examples
Example 1
Input
- methods =
['constructor', 'checkIn', 'checkIn', 'checkOut', 'checkOut', 'averageTime'] - arguments =
[[], [1, 'NYC', 5], [2, 'NYC', 7], [2, 'SFO', 8], [1, 'SFO', 10], ['NYC', 'SFO']]
Output
- answer =
[None, None, None, None, None, 3]
Leave a comment