The question was Kth Smallest Element in a Sorted Matrix.
Anónimo
First time encountering this problem, haven't solved before. Went with the brute-force first, convert this to an 1-D array, sort, and return k-th element. Satisfied, he pushed me to optimise further. Thought for ~1-2 min, and then explained the priority queue approach, where we kinda do like BFS, start from the smallest, and maintain a minheap, and when we pop (i, j), we add (i+1, j) and (i, j+1). Break the loop when you got the k-th element. Discussion about the problem and time complexity here got a little bit stretched. After getting satisfied, he pushed me to optimise even further. Seeing me struggle, gave me one hint (to think global), and then advised me to solve the problem of "given X, count numbers less than or equal to X in the matrix". Solved that using the top right start & elimination approach. And then briefly discussed about how to bring that idea here. Already 50 mins passed, so he advised me not to code, and we moved on to resume questions.