left
to the smallest element in the matrix and right
to the largest element.(m * n) / 2
since the matrix has an odd number of elements.mid
as the average of left
and right
.
b. Count the number of elements in the matrix less than or equal to mid
using a helper function that performs binary search on each row.
c. If the count is less than or equal to the median position, set left
to mid + 1
; otherwise, set right
to mid
.left
meets right
, the median value is found, and we return left
.