Median of Two Sorted Arrays
Updated
Problem statement
Given two sorted integer arrays nums1 and nums2, return the median of the two arrays as if they were merged.
Your algorithm must run in O(log(min(nums1.length, nums2.length))) time.
Function
findMedianSortedArrays(nums1: int[], nums2: int[]) → doubleExamples
Example 1
nums1 = [1,3]nums2 = [2]return = 2.0Merging the two arrays gives [1,2,3], and its middle value is 2.
Example 2
nums1 = [1,2]nums2 = [3,4]return = 2.5The middle values are 2 and 3, so the median is their average.
Constraints
0 <= nums1.length, nums2.length <= 10^5.1 <= nums1.length + nums2.length <= 2 * 10^5.-10^9 <= nums1[i], nums2[i] <= 10^9.- Both arrays are sorted in nondecreasing order.
More Bloomberg LP Onsite Interview questions
- Pascal's TrianglePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Valid Triangle NumberPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent WordsONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Shortest Subarray with Sum at Least KOracle · ONSITE INTERVIEWOracle interview questions
- Russian Doll EnvelopesGoogle · ONSITE INTERVIEWGoogle interview questions
- K-th Element of Two Sorted ArraysFlipkart · ONSITE INTERVIEW
- Allocate Minimum PagesAmazon · ONSITE INTERVIEW
- Minimum Processing Speed with Multiple RidersDoorDash · ONSITE INTERVIEWDoorDash interview questions
- Russian Doll EnvelopesInMobi · ONSITE INTERVIEWInMobi interview questions
- Median of Two Sorted ArraysRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Median of Two Sorted ArraysMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Russian Doll EnvelopesAirbnb · ONSITE INTERVIEWAirbnb interview questions
- Median of Two Sorted ArraysExpedia · ONSITE INTERVIEWExpedia interview questions