Find the Kth Slowest RPC Latency in a Batch

Last updated: November 29, 2026

Quick Overview

Given an unsorted array of RPC latencies in milliseconds and an integer k, return the kth largest latency (k = 1 is the slowest).

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Easy

0

0

0 solved


Given an unsorted array of RPC latencies in milliseconds and an integer k, return the kth largest latency (k = 1 is the slowest).

Google interviewers like this as a gateway into tail-latency talk: the kth slowest request is how p99 style metrics are computed on a batch. They check the heap solution, then ask about quickselect and its worst case.

What the Interviewer Expects
  • Gives the size-k min-heap solution
  • Explains quickselect and average O(n)
  • Mentions worst case and randomized pivots
  • Clarifies k is 1-indexed and duplicates count
  • Connects to percentile computation
Key Topics to Cover
Min-Heap
Quickselect
Selection
Percentiles
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
  • Implement quickselect with a random pivot
  • How would you get p99 over a stream that does not fit in memory?
  • How would you merge percentiles from many servers?
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 of n integers (latencies) and 1 <= k <= n.
  • Output: the kth largest value in sorted order, counting duplicates (so [5, 5, 3] with k = 2 gives 5).
  • No need to preserve the input....
High-Level Design

Heap approach: keep the k largest values in a min-heap. The root of that heap is the smallest of the top k, which is the kth largest overall. That is O(n log k) time, O(k) memory, and works on a strea...


Submit Your Answer
Markdown supported