Back to problems

Find kth smallest in sorted 2D matrix

Algorithm · ByteDance · Hard

Let matrix be an m x n grid of integers. Every row and every column is already arranged in non-decreasing order, and duplicate values may occur. You are given an integer k satisfying 1 <= k <= m * n. Return the value that would occupy position k if all cells were listed in non-decreasing order, counting repeated occurrences individually. Do not flatten the grid and fully sort all m * n values; your algorithm should be more efficient than that approach. Example 1:…

Checking your access…