Fastest Distance Span
MediumArrays ยท Optiver
A runner's pace is logged in 5-second intervals. distances[i] is the whole number of meters covered in interval i, run at a constant speed within that interval.
Return the highest average speed, in meters per second, over any continuous stretch of time in which the runner covers exactly target meters. The stretch may start and end part-way through intervals. If the runner covers fewer than target meters in total, return -1.0. Answers within 1e-6 are accepted.
Example 1
- Input:
- distances = [2, 4, 6, 8], target = 10
- Output:
- 1.5
- Explanation
- The last interval gives 8 m in 5 s, and the final 2 m of the interval before it takes 5/3 s more. That is 10 m in 20/3 s.
Example 2
- Input:
- distances = [3, 10, 8], target = 12
- Output:
- 1.92
Example 3
- Input:
- distances = [4, 0, 4], target = 6
- Output:
- 0.48
- Explanation
- The still interval between the two runs counts toward the elapsed time.
Constraints
1 <= distances.length <= 10^50 <= distances[i] <= 10^41 <= target <= 10^9