Search a 2D Matrix II
mediumSearch for a target in a sorted matrix where each row and each column is sorted ascending
Search a 2D Matrix II
Key Insight
Start top-right and eliminate one row/column per comparison.
Step 1Start at Top-Right
Target=5
1
04
17
211
315
42
55
68
712
819
93
106
119
1216
1322
1410
1513
1614
1717
1824
1918
2021
2123
2226
2330
24Move from (0,4) in a matrix sorted by rows and columns.
1 / 3