nums1 and nums2 of size m and
n respectively, return the median of the two sorted arrays.
The overall run time complexity should be O(log(m+n)).
O((m+n) log(m+n)) time — not optimal
for this problem's strict O(log(m+n)) requirement.
| Strategy | Time | Space | Key Idea / Trade-offs |
|---|---|---|---|
| My Answer — Merge & Sort | O((m+n)log(m+n)) | O(m+n) | Merge arrays, sort, pick middle. Simple but not optimal. Ignores sorted property. |
| AI 1 — Binary Search Partition | O(log(min(m,n))) | O(1) | Binary search on shorter array to find valid partition. Optimal time & space. |
| AI 2 — K-th Element Elimination | O(log(m+n)) | O(log(m+n)) | Finds k-th smallest by recursively discarding k/2 elements. Elegant recursion. |