Design Underground System

Medium

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

Input:["checkIn",45,"Leyton",3],["checkOut",45,"Waterloo",15],["getAverageTime","Leyton","Waterloo"]
Output:[null,null,12.0]
Explanation:

Average travel time calculation.

Input:["checkIn",123,"Downtown",5],["checkIn",456,"Uptown",8],["checkOut",123,"Central",20],["checkOut",456,"Central",25],["getAverageTime","Downtown","Central"],["getAverageTime","Uptown","Central"]
Output:[null,null,null,null,15.0,17.0]
Explanation:

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.

Input:["checkIn",789,"Mall",10],["checkOut",789,"Airport",35],["checkIn",789,"Airport",50],["checkOut",789,"Mall",70],["getAverageTime","Mall","Airport"],["getAverageTime","Airport","Mall"]
Output:[null,null,null,null,25.0,20.0]
Explanation:

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 or challenge other developers in a real-time coding battle!