← All problems
Median of Two Sorted Arrays
Given two sorted arrays, find the median of the combined sorted array in O(log(m+n)) time. The naive merge is O(m+n); the optimal solution partitions both arrays.
Complexity
Time O(log(min(m,n))), Space O(1)
Common pitfalls
- Merging (O(m+n) - too slow per spec)
- Odd/even total confusion
Your solution
Log in to save your code and track progress.