Skip to content

Practice Special Positions in a Binary Matrix

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#1582
LeetCode Problem

Special Positions in a Binary Matrix

Problem Statement

Given an m x n binary matrix mat, return the number of special positions in mat. A position (i, j) is called special if mat[i][j] == 1 and all other elements in row i and column j are 0 (rows and columns are 0-indexed).

Source: Special Positions in a Binary Matrix on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
mat = [[1,0,0],[0,0,1],[1,0,0]]
Output
1

# Example 2

Input
mat = [[1,0,0],[0,1,0],[0,0,1]]
Output
3

Constraints

m == mat.length
n == mat[i].length
1 <= m, n <= 100
mat[i][j] is either 0 or 1.

Related LeetCode Problems

Practice more problems similar to Special Positions in a Binary Matrix.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.