Cumulative Flight-Distance Alerts
Reported by candidates from Skydio's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Skydio OA reported in April 2024 hands you a drone path and asks when the odometer trips a threshold. Sounds like geometry. It's really a single pass with a running total. Segment lengths come from the Euclidean formula, you add them up, and every time the sum hits the threshold you record the index and zero the counter. Up to 100000 points, so linear time is the whole game. If you blank on the reset rule or the floating point details during the live assessment, StealthCoder is the invisible safety net that reads the problem and hands you a working solution.
The problem
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.0 return = [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.0 return = [] The path length is only 0.5 meters. Constraints 1 <= coordinates.length <= 100000. Every coordinate has exactly two finite values. 0 < threshold <= 1000000000.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The pattern is a simple simulation over an array. Loop from index 1, compute the distance between coordinates[i-1] and coordinates[i] with sqrt(dx*dx + dy*dy) (or hypot), add it to the accumulator, and if accumulator >= threshold, push i and set the accumulator to zero. The trick is that the reset discards any overshoot. Don't carry the remainder forward, because Example 1 only works if you reset to exactly zero. Pitfalls: the first point never emits since there's no segment yet, leftover distance at the end emits nothing, and the comparison is greater than or equal, not strictly greater. Floating point drift can bite on borderline cases, so compare directly and don't round. Also don't recompute prior sums, since that turns O(n) into O(n squared). If the live OA freezes you up, StealthCoder can cover you with the clean loop.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Cumulative Flight-Distance Alerts cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Skydio's OA.
Skydio reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Cumulative Flight-Distance Alerts FAQ
What's the trick in the Skydio distance alerts problem?+
There isn't a hidden one. It's a linear scan with an accumulator. Compute each segment's Euclidean length, add it, and when the total reaches the threshold, record the current index and reset to zero. The only real traps are the reset rule and the end-of-path leftover.
How hard is this Skydio OA question really?+
Easy. It's closer to a warm-up than a puzzle. The code is about ten lines. Most lost points come from off-by-one errors on the starting index or using strict greater than instead of greater than or equal.
Should the accumulator carry overshoot after an alert?+
No. The statement says reset the accumulator to zero when an alert fires. Example 1 confirms it: after index 2 the total restarts from nothing and only the later segments count toward index 4.
Do I need to worry about floating point precision?+
Not much. Use sqrt or hypot on the differences and compare the sum to the threshold directly. Don't round intermediate values. With doubles and up to 100000 points, plain accumulation is what the problem expects.
How do I prepare for this in 48 hours?+
Write the loop once from memory and test it on both examples. Check edge cases: a single coordinate, which returns an empty list, and a path that ends below the threshold. Then spend the rest of your time on other simulation and array problems.