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
Google
June 17, 2026
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
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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
  1. Identify the shorter array (let's call it A) and the longer array (B).
  2. Initialize binary search on the shorter array A.
  3. Define two pointers, left and right, to represent the curre...

Submit Your Answer
Markdown supported

Related Questions