Search a 2D Matrix Problem
Search a 2D Matrix Problem — ExecCode Medium DSA Practice
Solve the Search a 2D Matrix problem on ExecCode. Free online medium DSA practice in Binary Search. Write and run code in Java, C++, Python — no signup required to run.
Problem description
You are given an m x n integer matrix with the following two properties: every row is sorted in non-decreasing order, and the first integer of each row is greater than the last integer of the previous row. Given an integer target, return true if target is in the matrix, or false otherwise. You must write a solution in O(log(m × n)) time complexity.
Examples
Input matrix = [[1, 3, 5, 7], [10, 11, 16, 20], [23, 30, 34, 60]], target = 34; Output true. Input matrix = [[1, 3, 5, 7], [10, 11, 16, 20], [23, 30, 34, 60]], target = 13; Output false. Input matrix = [[1]], target = 1; Output true
Constraints
m == matrix.length n == matrix[i].length 1 ≤ m, n ≤ 100 -10⁴ ≤ matrix[i][j], target ≤ 10⁴
Practice Search a 2D Matrix free on ExecCode. Browse DSA problems, topic map, and placement guides.