Special Positions in a Binary Matrix Problem

Special Positions in a Binary Matrix Problem — ExecCode Easy DSA Practice

Solve the Special Positions in a Binary Matrix problem on ExecCode. Free online easy DSA practice in Arrays - Logic Building. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description You are given an m x n binary matrix mat, return the number of special positions in mat . Your task is to 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). Return the required answer exactly as shown in the examples.

Examples

Input {"mat": [[1, 0, 0], [0, 0, 1], [1, 0, 0]]}; Output 1. 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.

Practice Special Positions in a Binary Matrix free on ExecCode. Browse DSA problems, topic map, and placement guides.