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
Coding & Algorithms
Software Engineer
Nike
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

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
Binary search
Piecewise linear functions
Two pointers
Interpolation
Sensor data
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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 T(x)T(x) be the time at distance xx. A stretch starting at distance xx costs f(x)=T(x+D)−T(x)f(x) = T(x + D) - T(x). Between breakpoints (positions where xx or x+Dx + D is a sample distance) both terms are line...


Submit Your Answer
Markdown supported

Related Questions