Code Room
CodingMedium
Question
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) → intExamples
in
[[[1,4,7,11],[2,5,8,12],[3,6,9,16],[10,13,14,17]],5]out1What 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.
Learn the concepts
Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.
Run or narrate your approach, then ask the coach.