Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Special Positions in a Binary Matrix

XPChallenge Points: 10
levelLevel: Easy

You are given a binary matrix mat with m rows and n columns.
A cell (i, j) is considered special if:

  • mat[i][j] is 1, and

  • every other value in row i is 0, and

  • every other value in column j is 0

In simple terms, the cell must be the only 1 in both its row and its column.
Return how many such special cells exist in the matrix.

Example 1:

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

Output: 2

Explanation:

Special cells are at (0,1) and (2,2).

Example 2:

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

Output: 2

Explanation:

Special positions: (0,0) and (2,1).

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result