O80
Search a 2D Matrix II
Problem Statement & Objective
Write an efficient algorithm that searches for an integer target in an m x n matrix where rows and columns are sorted.
Function Signature (Python)
search_matrix(matrix: list[list[int]], target: int) -> boolInput & Output Contract
Output Rule:True veya False.
System Constraints
m == matris.length, n == matris[i].length
1 <= m, n <= 300
-10^9 <= matris[i][j], hedef <= 10^9Example Execution Walkthrough
matris = [
[1, 4, 7, 11, 15],
[2, 5, 8, 12, 19],
[3, 6, 9, 16, 22],
[10, 13, 14, 17, 24],
[18, 21, 23, 26, 30]
], hedef = 5 -> True
hedef = 20 -> FalseExample Test Scenarios (3)
Example 1: Mevcut
Input:
[[[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]],5]Expected Output:
trueExample 2: Yok
Input:
[[[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]],20]Expected Output:
falseExample 3: 1x1
Input:
[[[-5]],-5]Expected Output:
true