The problem. Given an n × n matrix where every row and every column is sorted in ascending order, return the kth smallest value in the whole matrix — in sorted order, so duplicates count, not the kth distinct value.
matrix = [[1, 5, 9], [10, 11, 13], [12, 13, 15]], k = 8 -> 13
matrix = [[-5]], k = 1 -> -5
matrix = [[1, 2], [1, 3]], k = 2 -> 1 (the two 1s both count)Free account
Sign up to read the rest of this lesson: 7 more sections, 3 drawings, a dry-run simulator and code in JavaScript, Python, Java and C++.
Still to come