Rolling Five-Second Flight-Distance Alerts
Problem statement
A drone reports one planar coordinate at each integer second. For every report index i > 0, compute the path length traveled during the most recent five seconds: sum the adjacent-segment lengths whose ending indices are from max(1, i - 4) through i.
Return every zero-based index where that rolling distance is at least threshold.
Function
rollingDistanceAlerts(coordinates: double[][], threshold: double) → int[]Examples
Example 1
coordinates = [[0.0,0.0],[0.3,0.0],[0.6,0.0],[0.9,0.0],[1.2,0.0],[1.5,0.0]]threshold = 1.0return = [4,5]At indices 4 and 5, the most recent four segments total 1.2 meters.
Example 2
coordinates = [[0.0,0.0],[0.1,0.0],[0.2,0.0]]threshold = 1.0return = []No rolling window reaches one meter.
Constraints
1 <= coordinates.length <= 100000.- Every coordinate has exactly two finite values.
0 < threshold <= 1000000000.