Kth smallest in a row-sorted matrix
Asked at DE Shaw, Optiver
You are given an n x n matrix whose every row is sorted in ascending order (and, in the classic version, every column too). Return the k-th smallest element in the whole matrix, counting duplicates.
matrix = [[ 1, 5, 9],
[10, 11, 13],
[12, 13, 15]]
k = 8 -> 13
Aim for time and memory.
Your answer
This one is open-ended. Work it through, then check your reasoning against the full solution.