Search 2D sorted matrix
You are given an m x n matrix where each row is sorted ascending left-to-right and each column is sorted ascending top-to-bottom. Given a target, return [row, col] of an occurrence (0-indexed), or [-1, -1] if absent. Aim for O(m + n). Constraints: 1 <= m, n <= 300, -10^9 <= values, target <= 10^9.
Implement
search_sorted_matrix(matrix: list[list[int]], target: int) → list[int]Examples
in
[[[1,4,7,11],[2,5,8,12],[3,6,9,16],[10,13,14,17]],5]out[1,1]What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 24 min
solution.py
InputExpectedGot
[[[1,4,7,11],[2,5,8,12],[3,6,9,16],[10,13,14,17]],5][1,1]not run yetsample