Given a matrix where every row and every column is sorted in nondecreasing order, return the kth smallest element. A min heap over the frontiers of each row gives an efficient solution.
matrix = sorted matrix, k = rank
kth smallest value in the matrix
Example 1:
Input:
matrix = [[1,5,9],[10,11,13],[12,13,15]] k = 8
Output:
13
Explanation:
The 8th smallest value in the matrix is 13.
Example 2:
Input:
matrix = [[1,2],[1,3]] k = 2
Output:
1
Explanation:
The sorted sequence is [1,1,2,3].