Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    Practice problems / Search a sorted matrix

    Search a sorted matrix

    Mediumbinary searchmatrix

    Each row of matrix is sorted ascending, and each row's first number is larger than the previous row's last. Return true if target is present, in O(log(m·n)).

    Example 1

    Input:  matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3
    Output: true

    Example 2

    Input:  matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 13
    Output: false

    Constraints

    • 1 ≤ rows, cols ≤ 100
    • -10⁴ ≤ values, target ≤ 10⁴

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

    /**
     * @param {int[][]} matrix
     * @param {int} target
     * @return {bool}
     */
    function searchMatrix(matrix, target) {
      
    }
    
    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.