Skip to content

Commit c0ca2cf

Browse files
authored
Update 0074-Search-a-2D-Matrix.md
1 parent 0f3795f commit c0ca2cf

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

dsa-solutions/lc-solutions/0000-0099/0074-Search-a-2D-Matrix.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
id: search-a-2D-matrix
33
title: Search a 2D matrix
44
difficulty: Medium
5-
sidebar_label: 0073-search2Dmatrix
5+
sidebar_label: 0074-search2Dmatrix
66
tags:
77
- Array
88
- Binary Search
@@ -17,7 +17,7 @@ tags:
1717

1818
## Problem Description
1919

20-
You are given an m x n integer matrix matrix with the following two properties:
20+
You are given an $m \times n$ integer matrix matrix with the following two properties:
2121

2222
- Each row is sorted in non-decreasing order.
2323
- The first integer of each row is greater than the last integer of the previous row.
@@ -32,13 +32,19 @@ You must write a solution in $O(log(m * n))$ time complexity.
3232
#### Example 1:
3333

3434
**Input**:
35-
Matrix = [[1,3,5,7], [10,11,16,20], [23,30,34,60]], target = 3
35+
```
36+
Matrix = [[1,3,5,7], [10,11,16,20], [23,30,34,60]]
37+
Target = 3
38+
```
3639

3740
**Output**: true
3841

3942
#### Example 2:
4043
**Input**:
41-
Matrix = [[1,3,5,7], [10,11,16,20], [23,30,34,60]], target = 13
44+
```
45+
Matrix = [[1,3,5,7], [10,11,16,20], [23,30,34,60]]
46+
Target = 13
47+
```
4248

4349
**Output**: false
4450

@@ -48,7 +54,7 @@ Matrix = [[1,3,5,7], [10,11,16,20], [23,30,34,60]], target = 13
4854
- m == matrix.length
4955
- n == matrix[i].length
5056
- 1 <= m, n <= 100
51-
- -10^4 <= matrix[i][j], target <= 10^4
57+
- -10<sup>4</sup> <= matrix[i][j], target <= 10<sup>4</sup>
5258

5359
### Approach
5460

@@ -146,8 +152,8 @@ class Solution {
146152

147153
Complexity Analysis
148154

149-
- Time Complexity: $O(log(NxM))$, where N = given row number, M = given column number.
155+
- Time Complexity: $O(log(N.M))$, where N = given row number, M = given column number.
150156

151157
Reason: We are applying binary search on the imaginary 1D array of size NxM.
152158

153-
- Space Complexity: $O(1)$ as we are not using any extra space.
159+
- Space Complexity: $O(1)$ as we are not using any extra space.

0 commit comments

Comments
 (0)