Google | Onsite | Busy Traffic
Anonymous User
8472

Given a list of cars traveling from point start to end with speed in the format [start, end, speed]. You need to return the list of smallest intervals (segments) and the average speed of vehicles in each of those intervals.

Used for road color coding as per traffic prediction used in google maps or lately uber.

Example 1:

Input: [[0, 14, 90], [3, 15, 80]]
Output: [[0, 3, 90], [3, 14, 85], [14, 15, 80]]
Explanation:
car1: [0, 14, 90] car 1 travels from point 0 to 14 with speed 90
car2: [3, 15, 80] car 2 travels from point 3 to 15 with speed 80

Segments:
[0, 3] with average speed 90
[3, 14] speed is (90 + 80) / 2 = 85, where we take the average of all cars here
[14, 15] with average speed is 80

Example 2:

Input = [[5, 15, 20], [10, 20, 30]]
Output = [[5, 10, 20], [10, 15, 25], [15, 20, 30]]

Example 3:

Input: [[5, 15, 20], [10, 20, 30], [7, 25, 10]]
Output: [[5, 7, 20], [7, 10, 15], [10, 15, 20], [15, 20, 20], [20, 25, 10]]
Comments (12)