FastPrepMedian of Two Sorted Arrays
Problems/Median of Two Sorted Arrays

Median of Two Sorted Arrays

JP Morgan Chase logoJP Morgan Chase● HardNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a JP Morgan Chase new grad onsite interview. The report names the median of two sorted arrays coding task. We chose the limits, the rules for empty arrays, the return interface and the explicit time target. Our version is about 85% the same as the reported question.

Return the median of the values in two sorted integer arrays a and b. For an odd total count, the median is the middle value. For an even total count, it is the average of the two middle values.

For this exercise, assume either array may be empty, but they cannot both be empty. Aim for logarithmic time in the shorter array's length.

Function

findMedianSortedArrays(a: int[], b: int[]) → double

Examples

Example 1

a = [1,3]b = [2]return = 2.0

The combined sorted order is [1, 2, 3], whose middle value is 2.

Example 2

a = [1,2]b = [3,4]return = 2.5

The middle values of [1, 2, 3, 4] are 2 and 3. Their average is 2.5.

Example 3

a = []b = [-2,0,8]return = 0.0

Only the second array contributes values. Its middle value is 0.

Constraints

  • 0 <= a.length <= 10000
  • 0 <= b.length <= 10000
  • -1000000 <= a[i], b[i] <= 1000000
  • Both arrays are sorted in nondecreasing order.
  • At least one array is nonempty.

More JP Morgan Chase Onsite Interview questions

  • LFU CacheONSITE INTERVIEW · Seen Nov 2026
  • LRU CacheONSITE INTERVIEW · Seen Nov 2026
  • Employees Above Average SalaryONSITE INTERVIEW · Seen Sep 2026
  • Highest-Earning Employees By DepartmentONSITE INTERVIEW · Seen Sep 2026
  • K Largest Integers in Descending OrderONSITE INTERVIEW · Seen Aug 2026
  • Tile a Three-Row Board with DominoesONSITE INTERVIEW · Seen Jan 2026
  • Two SumONSITE INTERVIEW · Seen Nov 2025
  • Intersection of Two ListsONSITE INTERVIEW · Seen Jan 2025
  • Maximum Subarray SumONSITE INTERVIEW · Seen Jan 2025
  • Fibonacci NumberONSITE INTERVIEW · Seen Nov 2024

Similar questions at other companies

  • 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
  • Split Array Largest SumBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Median of Two Sorted ArraysExpedia · ONSITE INTERVIEWExpedia interview questions
  • Search a Row- and Column-Sorted MatrixByteDance · ONSITE INTERVIEWByteDance interview questions

Interview reports that mention this question

  • JPMorgan Quant Stats Superdays: 3 Experiences (Part 3 of 3)

JP Morgan Chase interview experiences

  • JPMorgan Quant Modeling Superdays: 7 Experiences (Part 2 of 3)
  • JPMorgan Quant Intern Superday: 19 Experiences (Part 1 of 3)
  • JP Morgan Chase Data and AI Intern Superday: 11 Experiences
  • JPMorgan Code for Good India 2024: 6 Experiences (Part 5 of 5)
  • JPMorgan Code for Good India: 10 Experiences (Part 4 of 5)
All JP Morgan Chase interview questionsSee JP Morgan Chase hiring insights
Saved
class Solution {
    public double findMedianSortedArrays(int[] a, int[] b) {
        // Write your code here.
    }
}
Checking account…