Find the th smallest value in an matrix where each row and column is sorted in non-decreasing order.
Given an matrix of integers, each row sorted from left to right and each column sorted from top to bottom, return the th smallest element in the matrix.
The matrix may contain duplicate values, and the th smallest element is counted by position in the sorted order, not by distinct value.
matrix of size n x nkThe matrix satisfies:
Example 1
Input
matrix = [[1,5,9],[10,11,13],[12,13,15]], k = 8
Output
13
Explanation
The sorted order is [1,5,9,10,11,12,13,13,15], so the 8th smallest value is 13.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.