You are given a JSON log that records velocities of multiple vehicles at different timestamps. Your task is to identify two things: the vehicle that achieved the highest single speed, and the vehicle whose speeds varied the most (largest velocity range).
The input is a JSON array of objects. Each object has three fields:
timestamp (string): an ISO 8601 date-time when the reading was taken.vehicle_id (string): a unique identifier for the vehicle.velocity (number): the recorded speed at that moment.Example structure:
[
{"timestamp": "2023-01-01T00:00:00Z", "vehicle_id": "car_1", "velocity": 10},
{"timestamp": "2023-01-01T00:00:01Z", "vehicle_id": "car_2", "velocity": 15}
]
Your program should return an object with the following fields:
vehicle_id: the ID of the vehicle that reached the highest velocity.velocity: that maximum velocity value.max_range_vehicle_id: the ID of the vehicle with the largest velocity range.max_velocity_range: the size of that range.The velocity range of a vehicle is defined as the difference between its maximum and minimum recorded velocities across all timestamps.
Input:
[
{"timestamp": "2023-01-01T00:00:00Z", "vehicle_id": "car_1", "velocity": 10},
{"timestamp": "2023-01-01T00:00:01Z", "vehicle_id": "car_2", "velocity": 15},
{"timestamp": "2023-01-01T00:00:02Z", "vehicle_id": "car_1", "velocity": 15},
{"timestamp": "2023-01-01T00:00:03Z", "vehicle_id": "car_2", "velocity": 18}
]
Output:
{
"vehicle_id": "car_2",
"velocity": 18,
"max_range_vehicle_id": "car_1",
"max_velocity_range": 5
}
Explanation:
car_1 recorded velocities 10 and 15 → range = 5.car_2 recorded velocities 15 and 18 → range = 3.car_2.car_1.