Notice Period

Merged Median of Two Feeds

hard

Two weather stations each publish their day's temperature readings as a sorted list: feed_a and feed_b. The analyst needs the median of all readings combined — without paying for the merge.

Return the median of the two sorted lists as a float. If the combined count is even, return the average of the two middle values. Target O(log(min(m, n))); a full merge is the brute force you're here to beat.

Example 1
in feed_a = [1, 3], feed_b = [2]
out 2.0
Combined: [1, 2, 3] — median 2.
Example 2
in feed_a = [1, 2], feed_b = [3, 4]
out 2.5
Combined: [1, 2, 3, 4] — (2 + 3) / 2.
Constraints
  • · 0 <= len(feed_a), len(feed_b) <= 1000
  • · 1 <= len(feed_a) + len(feed_b)
  • · -10^6 <= values <= 10^6
  • · both lists sorted ascending
similar problem on LeetCode ↗
solution.pyloading python…
test results
Hit ▶ Run to test your code against the visible cases.