श्रीः
Matrix Search Problem | DSA Problem Solving
Problem Description
- We are given a matrix (2D array) having m rows and n columns (m ≥ 1, n ≥ 1).
- Within each row, the elements are sorted in non-descending order.
[That is, any element is at least as large as the previous element of the same row.]
- The 1st element of each row is at least as large as the last element of the previous row.
- We are also given a target value.
- Need to determine if the value is present in the matrix or not.
Illustrative Examples
Example 1
Matrix
| 3 | 5 | 5 | 8 |
| 12 | 14 | 15 | 15 |
Target: 14
Answer: target is present
Example 2
Matrix
| 2 | 7 |
| 7 | 9 |
| 12 | 20 |
Target: 7
Answer: target is present
Example 3
Matrix
| 2 | 5 | 7 |
| 10 | 12 | 12 |
| 12 | 15 | 20 |
Target: 8
Answer: target is not present
Here, we introduced the problem of searching for a value in a sorted matrix. In subsequent posts, we can look at different approaches to solving this.

Leave a Reply