Skip to interview prep
Apexed
Problem list112 / 125

112. Median of Two Sorted Arrays

HardBinary search

Given two sorted arrays a and b, return the median of all their values combined. The target complexity is O(log(min(m, n))).

Example 1

Input: a = [1, 3], b = [2]
Output: 2

Example 2

Input: a = [1, 2], b = [3, 4]
Output: 2.5

Constraints

  • 0 ≤ m, n ≤ 1000
  • m + n ≥ 1

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 5 hidden and sample tests.

Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.

Median of Two Sorted Arrays — coding interview practice — Apexed