Kth Smallest Element in a Sorted Matrix
MediumBinary Search
Decode it first. Clues, constraints, pattern and plan before any code.You are given an n x n grid matrix where every row and every column is sorted in ascending order. Return the kth smallest value in the grid, counting duplicates (it is the kth value in sorted order, not the kth distinct value). Aim for better than O(n²) memory.
matrix = [[1, 5, 9],
[10, 11, 13],
[12, 13, 15]], k = 8 → 13
matrix = [[-5]], k = 1 → -5Constraints
n == matrix.length == matrix[i].length1 <= n <= 300-10^9 <= matrix[i][j] <= 10^91 <= k <= n^2