Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    Practice problems / Median of two sorted arrays

    Median of two sorted arrays

    Hardbinary searcharraydivide and conquer

    a and b are sorted ascending. Return the median of all their elements together; with an even count it's the average of the two middle values. Aim for O(log(m + n)).

    Example 1

    Input:  a = [1,3], b = [2]
    Output: 2

    Example 2

    Input:  a = [1,2], b = [3,4]
    Output: 2.5

    (2 + 3) / 2 = 2.5.

    Constraints

    • 0 ≤ m, n ≤ 1000
    • 1 ≤ m + n ≤ 2000
    • -10⁶ ≤ values ≤ 10⁶

    Submit checks your solution against 10 tests, including hidden ones.

    /**
     * @param {int[]} a
     * @param {int[]} b
     * @return {double}
     */
    function findMedianSortedArrays(a, b) {
      
    }
    
    Sign in to run
    SeaCode

    Learn to code for real, online or at our branch in front of Cairo University, Giza.

    Learn

    • All courses
    • Interactive tutorials
    • Interview practice problems
    • Mock interview
    • Learning tracks
    • Code Arena
    • Workshops & Events
    • Knowledge library
    • Team projects

    Your account

    • Log in
    • Sign up
    • Learning plan
    • Certificates
    • Site map

    Contact us

    • WhatsApp
    • 010 9094 1104
    • In front of Cairo University, Giza

    © 2026 SeaCode. All rights reserved.