Special Positions in a Binary Matrix
EasyMatrixsimulation
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
You are given an m x n matrix mat containing only 0s and 1s. A cell (i, j) is **special** when mat[i][j] == 1 and every other cell in row i and in column j is 0.
Return the number of special cells.
Examples
Input: mat = [[1,0,0],[0,0,1],[1,0,0]]
Output: 1
Only (1,2) is special; (0,0) and (2,0) share column 0.
Input: mat = [[1,0,0],[0,1,0],[0,0,1]]
Output: 3
Each 1 is alone in both its row and its column.
Constraints
- 1 <= m, n <= 100
- mat[i][j] is 0 or 1
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.