Dsa
Heap
Easy
Kth Smallest Element in Matrix
Given a sorted matrix where each row and each column is sorted, find the Kth smallest element in the matrix. You need to efficiently find the Kth smallest element without flattening the matrix.
Input format:
- The first line contains two integers R and C, where R is the number of rows and C is the number of columns.
- The next R lines each contain C sorted integers.
- The last line contains the integer K.
Output format:
- Print the Kth smallest element in the matrix.
Example:
Input:
3 3
1 5 9
10 11 13
12 13 15
8
Output:
13
Key concepts
heapmatrixkth-smallest
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