Z53

Kth Smallest Element in a Sorted Matrix

Staff / Principal Engineer
Target Time: 40 - 50 Minutes
Type: NUMERIC

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) -> int

Input & 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^2

Example Execution Walkthrough

matris = [[1, 5, 9], [10, 11, 13], [12, 13, 15]], k = 8 -> 8. eleman 13

Example Test Scenarios (3)

Example 1
Input:[[[1,5,9],[10,11,13],[12,13,15]],8]
Expected Output:13
Example 2: 1x1
Input:[[[-5]],1]
Expected Output:-5
Example 3: Tekrarlı Eleman
Input:[[[1,2],[1,3]],2]
Expected Output:1
Loading Python Editor...
Input Parameters
[
  [
    [
      1,
      5,
      9
    ],
    [
      10,
      11,
      13
    ],
    [
      12,
      13,
      15
    ]
  ],
  8
]
Expected Output
13