Matrix Median

Binary Search on 2D Arrays DSA practice problem on Onlearn.

Difficulty: hard.

Topics: Finding the median of a row-wise sorted matrix of size MxN where MxN is odd., Matrices, Two-dimensional Array Traversal, Sorting, Brute Force, Binary Search, Time Complexity, Space Complexity, Arrays, binary search, array algorithms, sorting algorithms, matrix properties, matrix traversal, time complexity analysis, Median of Sorted Arrays, Matrix Search, Lower & Upper Bound.

Median in a Row wise Sorted Matrix Problem Statement Given a row wise sorted matrix of size M x N, where M is the number of rows and N is the number of columns, find the median in the given matrix. Note : M x N is odd. Input Specification The input consists of: An integer M, representing the number of rows. An integer N, representing the number of columns. A 2D integer array matrix of size M x N, where each row is sorted in non decreasing order. Output Specification Return an integer representing the median of the matrix. Constraints M N is odd. Sample Test Cases Example 1: Explanation: If we find the linear sorted array, the array becomes [1, 2, 3, 4, 5, 6, 7, 8, 9]. So, the median is 5. Example 2: Explanation: If we find the linear sorted array, the array becomes [1, 1, 2, 2, 3, 3, 4, 5, 7, 8]. So, the median is 3.