LeetCode 4 Median of Two Sorted Arrays - Why Naive Fails

The trap

Merge both arrays, then find the median at position (m + n) / 2.

Merging takes O(m+n)O(m + n) time and space.

The problem requires O(log(m+n))O(\log(m + n)). You need a way to find the median position without building the merged array.