Design Underground System
Description
Design an underground railway system tracking customer travel times. Implement checkIn, checkOut, and getAverageTime between any two stations. Return the result as an integer.
Examples
[["checkIn",45,"Leyton",3],["checkOut",45,"Waterloo",15],["getAverageTime","Leyton","Waterloo"]][null,null,12.0]Average travel time calculation.
[["checkIn",123,"Downtown",5],["checkIn",456,"Uptown",8],["checkOut",123,"Central",20],["checkOut",456,"Central",25],["getAverageTime","Downtown","Central"],["getAverageTime","Uptown","Central"]][null,null,null,null,15.0,17.0]Two different passengers travel to the same destination station. Customer 123 travels from Downtown to Central (20-5=15 minutes), while customer 456 travels from Uptown to Central (25-8=17 minutes). Each route maintains its own separate average.
[["checkIn",789,"Mall",10],["checkOut",789,"Airport",35],["checkIn",789,"Airport",50],["checkOut",789,"Mall",70],["getAverageTime","Mall","Airport"],["getAverageTime","Airport","Mall"]][null,null,null,null,25.0,20.0]Same customer makes round trip between two stations. First trip: Mall to Airport takes 25 minutes (35-10). Return trip: Airport to Mall takes 20 minutes (70-50). Direction matters - these are tracked as separate routes with different averages.
Constraints
- •
1 ≤ id, t ≤ 10⁶ - •
1 ≤ stationName.length ≤ 10
Ready to solve this problem?
Practice solo and sharpen your skills for technical interviews.