Dsa
Matrix
Easy
Matrix Median Calculation
Given an m x n matrix of integers, find the median of the matrix efficiently. The median is defined as the middle element when the elements are sorted. If the number of elements is even, it is the average of the two middle elements.
Input Format:
- The first line contains two integers, m and n, representing the dimensions of the matrix.
- The next m lines contain n integers each.
Output Format:
- A single floating point number representing the median of the matrix, rounded to 6 decimal places.
Example:
Input:
3 3
1 3 3
3 5 6
1 2 4
Output:
3.0
Key concepts
matrixmedian
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now