You are given a matrix of size m × n where each row is sorted in ascending order. Your task is to find the median of the matrix. The median is the middle element when all elements of the matrix are arranged in sorted order. If the total number of elements is odd, the median is the middle element.
Example 1
Input: matrix = [[1,3,5],[2,6,9],[3,6,9]]
Output: 5
Explanation: All elements in sorted order are [1,2,3,3,5,6,6,9,9]. The middle element is 5, which is the median.
Example 2
Input: matrix = [[1,2,3],[4,5,6],[7,8,9]]
Output: 5
Explanation: All elements in sorted order are [1,2,3,4,5,6,7,8,9]. The middle element is 5, which is the median.
Example 3
Input: matrix = [[2,4,6],[3,5,7],[8,9,10]]
Output: 6
Explanation: All elements in sorted order are [2,3,4,5,6,7,8,9,10]. The middle element is 6, which is the median.
Sign in to write, run, and submit your solution against the full test suite.