Code RoomSearch sorted matrix
MediumPrep Room Coding #784

Search sorted matrix

CodingAlgorithms & data structuresMid–Senior~20 min

Given an m x n integer matrix where each row is sorted ascending left-to-right and each column is sorted ascending top-to-bottom, determine whether a target value exists in the matrix. Return True or False. Aim for O(m + n) time. The matrix has at least one row and one column.

Implement
search_matrix_staircase(matrix: list[list[int]], target: int) → bool
Examples
in[[[1,4,7,11],[2,5,8,12],[3,6,9,16],[10,13,14,17]],5]outtrue
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 20 min
InputExpectedGot
[[[1,4,7,11],[2,5,8,12],[3,6,9,16],[10,13,14,17]],5]truenot run yetsample