FastPrepFastest Average Speed over a Rolling Kilometer
Problems/Fastest Average Speed over a Rolling Kilometer

Fastest Average Speed over a Rolling Kilometer

Optiver logoOptiver● HardFULLTIMEOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report supplies consecutive five-second distance samples, an exactly one-kilometer fastest-average objective, and a two-pointer approach. It omits boundary interpolation, units, precision, bounds, and the no-kilometer result; the piecewise-constant-pace contract supplies those details. The judged task matches the report at about 82%.

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[]) → double

Examples

Example 1

meters = [400,400,400]return = 80.0

At 80 meters per second throughout, exactly 1000 meters takes 12.5 seconds.

Example 2

meters = [100,600,600,100]return = 120.0

The fastest kilometer starts and ends inside the two central intervals and takes 1000 / 120 seconds.

Example 3

meters = [200,300,400]return = -1.0

The complete run covers only 900 meters.

Constraints

  • 1 <= meters.length <= 100000.
  • 1 <= meters[i] <= 10000.
  • The answer is accepted within 10^-6 absolute or relative error.

More Optiver problems

  • Power Cell BankOA · Seen Nov 2026
  • Overheat Prevention ControllerOA · Seen Oct 2026
  • Count Straight-Line Word Occurrences in a GridOA · Seen Sep 2026
All Optiver interview questionsSee Optiver hiring insights
Saved
class Solution {
    public double fastestKilometerSpeed(int[] meters) {
        // Write your solution here.
    }
}
Checking account…