Implement the function nearest_waypoint_indices(route, distances, threshold) that simulates travel along a path of waypoints and returns for each cumulative distance the index of the nearest waypoint, if it falls within the threshold.
You are given a route route, which is a list of 2D points (waypoints), and a strictly increasing list of cumulative arc lengths distances. The journey begins at the first waypoint and proceeds along the straight‑line segments connecting consecutive waypoints in order. For each distance in distances, compute the exact position on the route that corresponds to having traveled that far. From that position, identify the waypoint (among all waypoints) that is closest in Euclidean distance. If the closest waypoint is no more than threshold miles away, return its 0‑based index; otherwise, return -1 for that distance.
If two or more waypoints are equally close and within the threshold, output the one with the smallest index.
Return an array of integers, one result per element of distances.
Example 1:
Input: coordinates = [[0, 0], [3, 0], [7, 0]], distances = [2, 5, 6], threshold = 1.5
Output: [1, -1, 2]
Explanation: The route is (0,0) → (3,0) → (7,0). <img src="https://cgppcnnkwbfiieexbrea.supabase.co/storage/v1/object/public/question-images/sources/55c71b586c90107b49ff.png" alt="" width="500" />
Example 2:
Input: coordinates = [[0, 0], [4, 0]], distances = [4], threshold = 0.01
Output: [1]
Example 3:
Input: coordinates = [[0, 0], [5, 0], [5, 5]], distances = [3, 5, 8], threshold = 2.0
Output: [1, 1, 2]
Constraints:
2 ≤ coordinates.length ≤ 10^41 ≤ distances.length ≤ 10^4coordinates[i].length == 2coordinates[i][0] and coordinates[i][1] are integers, and distances[i] is a non-negative integer0 ≤ coordinates[i][0], coordinates[i][1] ≤ 10^60 ≤ distances[i] ≤ total path lengthdistances is strictly increasing0 < threshold ≤ 100.0