Kth Smallest Latency Gap Among All Pairs of Probe Measurements
Last updated: November 29, 2026
Quick Overview
Given latency measurements from network probes and an integer k, return the k-th smallest absolute difference among all pairs of distinct measurements.
0
0
0 solved
Given latency measurements from network probes and an integer k, return the k-th smallest absolute difference among all pairs of distinct measurements.
A Google onsite Hard problem framed around analyzing jitter between probes in a global network. The interviewer checks binary search on the answer and a two-pointer pass that counts pairs with difference at most d in linear time.
What the Interviewer Expects
- Avoids generating all O(n^2) pairs
- Binary searches on the difference value
- Counts pairs with gap at most d using a sliding left pointer
- Explains why the result is an actual pair difference
- States O(n log n + n log W) time
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
- What if the values are floating point?
- How would you return the pair itself?
- What if measurements are streaming and k is fixed?
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: list
latof integers with at least two values, integerkwith1 <= k <= n(n-1)/2. - Output: the k-th smallest value of
|lat[i] - lat[j]|over pairsi < j....
High-Level Design
Sort the values. Define count(d) as the number of pairs with difference at most d. It is non-decreasing in d, so the answer is the smallest d with count(d) >= k, found by binary search over ...