Medium
Search a Sorted 2D Matrix
Medium
74 submissions
25 coins
+100 XP
Binary Search
Matrix
Problem Description
Each row of `matrix` is sorted ascending, and the first value of each row is greater than the last value of the previous row. Return whether `target` is in the matrix, in O(log(rows · cols)) time.
**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
```
**Example 3:**
```
Input: matrix = [[1]], target = 1
Output: true
```
Constraints
- `1 <= rows, cols <= 100`
Need help?
Connect with expert programmers for real-time collaborative coding, video meetings, and whiteboard sessions via CodeConnect.
Video Call
Whiteboard
Live Coding
Screen Share