Given a sorted matrix (sorted row-wise and column-wise) of size n x n, find the kth smallest element in the matrix. Input Format: The first line contains the size of the matrix (n) and the value of k, separated by a space. The next n lines contain the matrix elements, with each row on a new line and elements separated by spaces. Output Format: The kth smallest element in the matrix.
Example 1
Input: 3 8 1 5 9 10 11 13 12 13 15
Output: 13
The 8th smallest element in the matrix is 13.
Constraints
Hints
Given a sorted matrix (sorted row-wise and column-wise) of size n x n, find the kth smallest element in the matrix. Input Format: The first line contains the size of the matrix (n) and the value of k, separated by a space. The next n lines contain the matrix elements, with each row on a new line and elements separated by spaces. Output Format: The kth smallest element in the matrix.
Example 1
Input: 3 8 1 5 9 10 11 13 12 13 15
Output: 13
The 8th smallest element in the matrix is 13.
Constraints
Hints