Back to DSA sheet
Design Underground System
MediumArraysBuild a system with checkIn(id, station, t), checkOut(id, station, t), and getAverageTime(start, end) returning the average travel time of all trips from start to end so far.
Input format (stdin): the first line has q. Each line is 'in id station t', 'out id station t', or 'avg start end'. For each avg, print the average with one decimal place.
Examples
Input: 5
in 1 A 3
out 1 B 8
in 2 A 10
out 2 B 15
avg A B
Output: 5.0
Two trips A->B took 5 each, average 5.0.
Constraints
- 1 <= q <= 10^4
- times are non-negative integers
Sheets
NeetCode 250
design-underground-system.cpp1 sample tests
Loading editor
Test results
Run the sample tests to check your solution against expected output.
Custom input (stdin)
Output
Run your code to see its output.