← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
Design a class CarAverageSpeeds that supports two operations on a stream of (carId, speed) records:
record(int carId, int speed) — record that a car with the given id was observed travelling at the given speed (mph). Each call is a new observation.
getAverage(int carId) — return the current average speed (mph) of all observations for that car, or –1.0 if no observations exist for it.
getOverallAverage() — return the current average speed (mph) across all observations ever recorded, or –1.0 if no observations exist.
All averages must be computed in O(1) time per query. The system must handle up to 10^8 total observations and 10^6 distinct cars efficiently.