Problem
You get a matrix of integers matrix with m rows and n columns, and an integer target. A matrix is a grid of numbers in rows and columns.
Each row is in non-decreasing order. Non-decreasing order means that each item is equal to or greater than the item before it. The first item of each row is greater than the last item of the row above it.
Return true if target is in matrix, and false if it is not. Your solution must run in O(log(m * n)) time.
Example 1
- Input:
- matrix = [[2,4,7,9],[12,15,18,20],[25,31,40,52]], target = 18
- Output:
- true
- Explanation:
- The value 18 is in the second row.
Example 2
- Input:
- matrix = [[2,4,7,9],[12,15,18,20],[25,31,40,52]], target = 10
- Output:
- false
- Explanation:
- The value 10 is greater than the last item of the first row and less than the first item of the second row.
Constraints
- m == matrix.length
- n == matrix[i].length
- 1 <= m, n <= 100
- -10^4 <= matrix[i][j], target <= 10^4
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Search a 2D Matrix II
Coding · Array · Binary Search · Divide and Conquer
- Escape the Spreading Fire
Coding · Array · Binary Search · Breadth-First Search
- Find the Safest Path in a Grid
Coding · Array · Binary Search · Breadth-First Search
- Leftmost Column with at Least a One
Coding · Array · Binary Search · Interactive
Sources · 2 references
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 3 records
Amazon
Leetcode 74. Search a 2D Matrix
Reported Jun 3, 2026 · 1 source report
SENIOR
Source snapshot: Nov 12, 2026
View sourceMeta
Leetcode 74. Search a 2D Matrix
Reported May 20, 2025 · 3 source reports
MID_LEVEL, SENIOR
Source snapshot: Nov 12, 2026
View sourceMotive
Leetcode 74. Search a 2D Matrix
Reported Apr 23, 2025 · 1 source report
MID_LEVEL
Source snapshot: Nov 12, 2026
View source
LeetCode company tags · 4 records
Goldman Sachs
Search a 2D Matrix
Reported date not specified · Source window: 3mo