Fastest Segment of a Target Distance in a GPS Run Trace
Last updated: November 29, 2026
Quick Overview
A run is recorded as samples of elapsed time and cumulative distance. Assuming constant speed between consecutive samples, find the minimum time needed to cover a target distance (for example 1 km or 5 km) over any contiguous stretch of the run, where the stretch may start and end between samples.
Nike
November 29, 20260
0
0 solved
A run is recorded as samples of elapsed time and cumulative distance. Assuming constant speed between consecutive samples, find the minimum time needed to cover a target distance (for example 1 km or 5 km) over any contiguous stretch of the run, where the stretch may start and end between samples.
Nike Run Club shows best efforts such as fastest 1K and fastest 5K, computed from noisy GPS traces with pauses. In the style of a Nike onsite coding round, the interviewer looks for the key insight that an optimal stretch has one endpoint on a sample, correct interpolation, and careful handling of pauses where distance stays flat.
What the Interviewer Expects
- Models time as a piecewise-linear function of distance and interpolates correctly
- Proves or argues that an optimal segment has at least one endpoint at a sample point
- Handles flat stretches (pauses) by choosing the latest start time and earliest end time
- Achieves O(n log n) or O(n) instead of brute force over all pairs
- Covers edge cases: total distance shorter than target, two samples, duplicate distances
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you turn the binary searches into a two-pointer O(n) pass?
- GPS noise creates fake 2 second sprints. How would you guard best-effort records against them?
- How would you compute best efforts for 400 m, 1 km, 1 mile, 5 km and 10 km in one pass?
- Auto-pause removes time spent stopped. How does that change the input or the answer?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: times strictly increasing seconds, dists non-decreasing cumulative meters, same length, and target meters. Output: the minimum duration over all stretches whose distance is exactly `targe...
High-Level Design
Let be the time at distance . A stretch starting at distance costs . Between breakpoints (positions where or is a sample distance) both terms are line...