Given an n x n matrix where each row and column is sorted in ascending order, find the kth smallest element in the matrix.
Binary search on the answer value (not index). Count elements <= mid. The kth smallest is the smallest value v such that count(v) >= k.
- lo=matrix[0][0], hi=matrix[n-1][n-1].
- For mid, count elements <= mid by traversing rows from bottom-left.
- If count >= k: hi=mid. Else lo=mid+1.
- lo converges to the kth smallest element.
- Time Complexity: O(N log(max-min))
- Space Complexity: O(1)