You are a Software Engineer at a massive automated warehouse. The warehouse stores crates in a square grid (n x n).
You could pull all the crates out and sort them in a long line, but that takes too much memory (O(n^2)). The warehouse computer is old—it needs a solution with better memory efficiency.
Given an n x n matrix where:
Return the kᵗʰ smallest element in the matrix.
Write a function that takes a 2D integer matrix matrix and an integer k, and returns the kᵗʰ smallest element.
matrix = [[1, 5, 9], [10, 11, 13], [12, 13, 15]], k = 8[1, 5, 9, 10, 11, 12, 13, 13, 15]13