Skip to content

Practice Kth Smallest Element in a Sorted Matrix

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#378
LeetCode Problem

Kth Smallest Element in a Sorted Matrix

Problem Statement

Given an n x n matrix where each of the rows and columns is sorted in ascending order, return the kth smallest element in the matrix. Note that it is the kth smallest element in the sorted order, not the kth distinct element. You must find a solution with a memory complexity better than O(n^2).

Source: Kth Smallest Element in a Sorted Matrix on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
matrix = [[1,5,9],[10,11,13],[12,13,15]], k = 8
Output
13

# Example 2

Input
matrix = [[-5]], k = 1
Output
-5

Constraints

n == matrix.length == matrix[i].length
1 <= n <= 300
-10^9 <= matrix[i][j] <= 10^9
All the rows and columns of matrix are guaranteed to be sorted in non-decreasing order.
1 <= k <= n^2

Related LeetCode Problems

Practice more problems similar to Kth Smallest Element in a Sorted Matrix.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.