Search a 2D Matrix
Return true if target exists in the matrix.
Examples
Input: [[[1,3,5,7],[10,11,16,20],[23,30,34,60]],3]
Output:
Input: [[[1,3,5,7],[10,11,16,20],[23,30,34,60]],13]
Output:
Hints
Consider the matrix as a flattened 1D array where each row is concatenated sequentially. The total number of elements is `rows * cols`.
Perform a binary search on the virtual 1D array by calculating the middle index, then converting it to 2D coordinates (row, col) using integer division and modulus operations.
Optimize the search by leveraging the sorted property of the matrix: discard half of the search space in each iteration by comparing the target with the middle element and adjusting the search range accordingly.
Search a 2D Matrix
Return true if target exists in the matrix.