Median Latency Across Two Sorted Server Log Arrays
Last updated: November 29, 2026
Quick Overview
Two data centers each report request latencies as a sorted array. Return the median of the combined data in O(log(min(m, n))) time, without merging the arrays.
Meta
November 29, 20260
0
0 solved
Two data centers each report request latencies as a sorted array. Return the median of the combined data in O(log(min(m, n))) time, without merging the arrays.
Percentile monitoring across regions is everyday work at Meta, and this is the well known binary-search partition problem. Interviewers look for the partition invariant, correct sentinel handling at the array edges, and binary searching on the shorter array.
What the Interviewer Expects
- Binary searches a cut in the shorter array
- Derives the matching cut in the longer array from total size
- Checks max-left <= min-right on both sides
- Uses infinities as sentinels at array edges
- Handles odd and even combined lengths
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
- Generalize to the k-th smallest element of the union.
- Compute the median across 100 sorted arrays.
- The arrays are on different machines and very large; how would you estimate p99 cheaply?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Both arrays sorted ascending, combined length at least 1. Return a float for even totals and the middle value for odd totals. Target O(log(min(m, n)))....
High-Level Design
Cut A after i elements and B after j elements with i + j = (m + n + 1) // 2, so the left halves together hold the lower half (one extra element when the total is odd). The cut is correct when `A[i-1] ...