Fastest Average Speed over a Rolling Kilometer
Problem statement
meters[i] is the distance traveled during the i-th consecutive five-second interval. Assume speed is constant within each interval.
Among every continuous segment of the run covering exactly 1000 meters, return the maximum average speed in meters per second. A segment boundary may split an interval proportionally. Return -1.0 when the total distance is less than 1000 meters.
Function
fastestKilometerSpeed(meters: int[]) → doubleExamples
Example 1
meters = [400,400,400]return = 80.0At 80 meters per second throughout, exactly 1000 meters takes 12.5 seconds.
Example 2
meters = [100,600,600,100]return = 120.0The fastest kilometer starts and ends inside the two central intervals and takes 1000 / 120 seconds.
Example 3
meters = [200,300,400]return = -1.0The complete run covers only 900 meters.
Constraints
1 <= meters.length <= 100000.1 <= meters[i] <= 10000.- The answer is accepted within
10^-6absolute or relative error.