Median of Two Sorted Arrays
Last updated: June 17, 2026
Quick Overview
Given two sorted arrays, find their median in O(log(min(m,n))) time. A classic binary search problem that tests divide-and-conquer thinking, frequently asked at Google.
Google
Coding & Algorithms
Software Engineer
Software Engineer
Onsite
Coding & Algorithms
Hard
288
0
138 solved
Given two sorted arrays, find their median in O(log(min(m,n))) time. A classic binary search problem that tests divide-and-conquer thinking, frequently asked at Google.
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Problem Analysis
The problem at hand is to find the median of two sorted arrays, which can be solved efficiently using a binary search approach. The key observation is that the median divides the combined arrays into ...
Approach
- Identify the shorter array (let's call it
A) and the longer array (B). - Initialize binary search on the shorter array
A. - Define two pointers,
leftandright, to represent the curre...
Submit Your Answer
Markdown supported