FDEInterviews logoFDE/Interviews
Coding & DSA / 79
hardGoogleAmazonAdobe

Find the median of two sorted arrays in logarithmic time

The O(log(min(m,n))) answer binary-searches a partition on the shorter array so the left halves of both arrays together hold exactly half the elements. The whole problem is one invariant plus careful boundary handling for empty sides and odd versus even totals.

Updated Aug 2026 · Grounded in real Forward Deployed Engineer interview loops and written to a senior-engineer editorial bar.

The O(log(min(m,n))) answer binary-searches a partition on the shorter array so the left halves of both arrays together hold exactly half the elements. The whole problem is one invariant plus careful boundary handling for empty sides and odd versus even totals.

Unlock the other 466 answers · ₹2,000 / $25Your progress and mastery stay saved · 6 months · one payment · no auto-renew
UP NEXT ON YOUR JOURNEY
FEDITOR'S NOTE

Merging to the midpoint is O(m+n) and many candidates stop there; it is a fine warm-up answer but not what 'log time' asks for. The partition solution is correctness-dense: the cut position on array A determines the cut on B by arithmetic, and the entire correctness rests on four comparisons at the boundary using plus and minus infinity sentinels for the empty edges. Binary-searching the longer array works but you must search the smaller one to keep the bound at log(min(m,n)) and to make the index arithmetic stay in range.

DISCUSSION · 0

No comments yet — be the first to share your approach.