Z53
Kth Smallest Element in a Sorted Matrix
Problem Statement & Objective
Given an n x n matrix where each of the rows and columns is sorted in ascending order, find the kth smallest element in the matrix.
Function Signature (Python)
kth_smallest_matrix(matrix: list[list[int]], k: int) -> intInput & Output Contract
Output Rule:k'ıncı en küçük sayı tam sayısı.
System Constraints
n == matris.length == matris[i].length
1 <= n <= 300
-10^9 <= matris[i][j] <= 10^9
1 <= k <= n^2Example Execution Walkthrough
matris = [[1, 5, 9], [10, 11, 13], [12, 13, 15]], k = 8 -> 8. eleman 13Example Test Scenarios (3)
Example 1
Input:
[[[1,5,9],[10,11,13],[12,13,15]],8]Expected Output:
13Example 2: 1x1
Input:
[[[-5]],1]Expected Output:
-5Example 3: Tekrarlı Eleman
Input:
[[[1,2],[1,3]],2]Expected Output:
1