Search A 2d Matrix - 2

medium
1. Write an efficient algorithm that searches for a target value in an m x n integer matrix. The matrix has the following properties:
a). Integers in each row are sorted in ascending from left to right.
b). Integers in each column are sorted in ascending from top to bottom.

Input Format

Input is managed for you

Output Format

Output is managed for you

Constraints

m == matrix.length
n == matrix[i].length
1 <= n, m <= 300
-10^9 <= matix[i][j] <= 10^9
-10^9 <= target <= 10^9

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
5 5
1 4 7 11 15
2 5 8 12 20
4 6 9 16 22
10 13 14 17 24
18 21 23 26 30
12
Output
true
Previous
Search A 2d Matrix
Next
Find Pair With Given Difference

Related Questions