Dsa
Heap
Easy
Kth Smallest Element in a Matrix
You are given a 2D matrix in which each row is sorted in ascending order. Implement a program that finds the k-th smallest element in the matrix. The input will start with the dimensions of the matrix followed by the elements of the matrix. Print the k-th smallest element or 'Invalid' if k is out of range. The program should read input until EOF.
Example:
Input:
3 3
1 5 9
10 11 13
12 13 15
k=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