Number of Submatrices That Sum to Target
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Given an integer matrix matrix and an integer target, count the non-empty axis-aligned rectangular submatrices whose elements sum to target.
A submatrix is determined by its top row r1, bottom row r2, left column c1, and right column c2 (with r1 <= r2, c1 <= c2); two submatrices are different if any of these four coordinates differ, even when their contents are equal.
Aim for O(rows^2 * cols) time.
Examples
Constraints
- 1 <= matrix.length <= 100
- 1 <= matrix[0].length <= 100
- -1000 <= matrix[i][j] <= 1000
- -10^8 <= target <= 10^8
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.