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.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

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
Binary Search on Answer
Two Pointers
Sorting
Counting Pairs
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
  • 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 Problems
Sample Answer
Requirements
  • Input: list lat of integers with at least two values, integer k with 1 <= k <= n(n-1)/2.
  • Output: the k-th smallest value of |lat[i] - lat[j]| over pairs i < 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 ...


Submit Your Answer
Markdown supported