An Alten Calsoft Labs data-processing component receives a matrix whose rows and columns are sorted in nondecreasing order. Given the matrix and an integer k, return the kth smallest element in the matrix, counting duplicate values as separate elements.
Implement an efficient solution without flattening and sorting the entire matrix.
matrix, a non-empty rectangular two-dimensional array of integers, and k, a one-based rank.k when all matrix elements are ordered from smallest to largest.def kth_smallest(matrix, k):