Practice Search a 2D Matrix
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Given an m by n matrix and target, return whether target occurs in the matrix. Each row is sorted in nondecreasing order, and the first value of every row after the first is greater than the final value of the preceding row. The search must take O(log(m * n)) time.
Source: Search a 2D Matrix on LeetCode. Use the original task for its coding environment and submissions.
Examples
# 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
m == matrix.length
n == matrix[i].length
1 <= m, n <= 100
-10^4 <= matrix[i][j], target <= 10^4
Related LeetCode Problems
Practice more problems similar to Search a 2D Matrix.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.