Cumulative Flight-Distance Alerts
Problem statement
A drone reports planar coordinates in travel order. Starting with the first report, accumulate the Euclidean length of every traveled segment. Whenever the accumulated distance is at least threshold, emit the current zero-based coordinate index and reset the accumulator to zero.
Return all emitted indices in increasing order. Distance left after the final report does not emit an alert.
Function
distanceAlerts(coordinates: double[][], threshold: double) → int[]Examples
Example 1
coordinates = [[0.0,0.0],[0.5,0.0],[1.0,0.0],[1.1,0.3],[2.0,1.0]]threshold = 1.0return = [2,4]The first two segments total one meter. After reset, the final two segments exceed one meter.
Example 2
coordinates = [[0.0,0.0],[0.3,0.4]]threshold = 1.0return = []The path length is only 0.5 meters.
Constraints
1 <= coordinates.length <= 100000.- Every coordinate has exactly two finite values.
0 < threshold <= 1000000000.