Code RoomCount target in grid
MediumPrep Room Coding #989

Count target in grid

CodingAlgorithms & data structuresMid–Senior~20 min

Given an m x n matrix in which each row is sorted in ascending order left-to-right and each column is sorted in ascending order top-to-bottom (but rows are NOT globally ordered relative to each other), count how many cells equal a given target. Aim for O(m + n) using the staircase walk; do not binary search every row. Dimensions up to 300 x 300.

Implement
count_in_sorted_matrix(matrix: list[list[int]], target: int) → int
Examples
in[[[1,4,7,11],[2,5,8,12],[3,6,9,16],[10,13,14,17]],5]out1
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]1not run yetsample