dsa · easy
Search a 2D Matrix
GreyOrangeArrayBinary SearchFoundation
Each row is sorted; first of each row is greater than last of the previous. Return whether target is in matrix.
Arguments
matrix— the 2D grid / matrixtarget— the value you are searching for or summing to
**Example**
`` Input: [[1,3,5,7],[10,11,16,20],[23,30,34,60]] 3 Output: True ``
Constraints
1 <= m, n <= 100 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: [[1,3,5,7],[10,11,16,20],[23,30,34,60]] 3 Expected: true
Example 2
Input: [[1,3,5,7],[10,11,16,20],[23,30,34,60]] 13 Expected: false