Median Latency Across Two Sorted Regional Latency Logs
Last updated: November 29, 2026
Quick Overview
Two AWS regions each produce a sorted list of request latencies. Return the median of the combined data in O(log(min(m, n))) time without merging the lists.
Amazon
November 29, 20260
0
0 solved
Two AWS regions each produce a sorted list of request latencies. Return the median of the combined data in O(log(min(m, n))) time without merging the lists.
A classic Hard binary search that Amazon onsite interviewers use to test partition reasoning under pressure, framed as reporting a cross-region p50 latency. Strong candidates binary search the partition of the shorter list and handle empty sides with sentinels.
What the Interviewer Expects
- Explain the O(m + n) merge baseline first
- Binary search a cut i in the shorter list and derive the cut j in the other
- Check the partition condition maxLeft <= minRight on both sides
- Use infinities for cuts at the ends
- Handle odd and even total 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
- How would you find the kth smallest element instead of the median?
- What if there were many regions, not just two?
- How would you compute an approximate p99 over streaming data instead?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Inputs: two sorted lists a and b, total length at least 1. Output: the median as a float (average of the middle two for even totals)....
High-Level Design
Ensure a is the shorter list. Choose i elements from a and j = half - i from b for the left half, where half = (m + n + 1) // 2. The partition is correct when a[i-1] <= b[j] and b[j-1] <= a[i]. If a[i...