Problem title
Difficulty
Avg time to solve

Kevin and the tower of coins
Moderate
25 mins
Distribution of Money
Easy
15 mins
Letter Case Permutation
Moderate
15 mins
Product of the Last K Numbers
Easy
15 mins
Kevin And The Number On A Dice
Easy
10 mins
Digit Count In Range
Moderate
25 mins
Maximum Distinct Blocks
Easy
10 mins
Flatten 2D array
Easy
20 mins
Nearest Pallindrome
Moderate
30 mins
Find a Corresponding Node of a Binary Tree in a Clone of That Tree
Easy
20 mins

# Special Cells in Binary Matrix

Difficulty: EASY
Contributed By
Avg. time to solve
30 min
Success Rate
75%

Problem Statement

#### Ninja is observing a Binary matrix of size N * M . A Binary Matrix is made up of only 0’s and 1’s. Ninja wants to know the number of special cells in the matrix. The conditions of a cell to be a special cell are:

``````The value of M[i][j] should be 1.
All other cells of row i should be 0.
All other cells of column j should be 0.
``````

#### You are given the matrix ‘MAT’ of size N * M. Your task is to find the number of special cells in the given matrix.

##### For Example
``````For the matrix :
1  0  0
0  0  0
0  1  0

The Answer will be 2 as cell (0,0) and (2,1) are special.(Indexing is 0 based).
``````
##### Input Format:
``````The first line of the input contains an integer, 'T,’ denoting the number of test cases.

The first line of each test case contains two integers,' N’ and ‘M’ denoting the number of rows and columns.

The next line of each test case has ‘N’ lines that have M values corresponding to the matrix ‘MAT’.
``````
##### Output Format:
``````For each test case, print an integer corresponding to the number of special cells in the matrix.

Print the output of each test case in a separate line.
``````
##### Note:
``````You do not need to print anything. It has already been taken care of. Just implement the given function.
``````
##### Constraints:
``````1 <= T <= 10
1 <= N <= 1000.
1 <= M <= 1000.

Time limit: 1 sec
``````
##### Sample Input 1:
``````2
3 3
1 0 0
0 0 0
0 1 0
4 3
1 0 0
0 0 1
0 0 0
0 1 1
``````
##### Sample Output 1:
``````2
1
``````
##### Explanation of sample input 1:
``````For the first test case,
There are two special cells having index (0,0) and (2,1).Hence, the answer is 2.

For the second test case:
There is only one cell that is special having an index (0,0). Hence, the answer is 1.
``````
##### Sample Input 2:
``````2
4 4
0 1 0 0
0 0 0 0
0 0 0 0
0 0 0 1
4 3
0 1 0
0 0 1
0 1 0
0 0 0
``````
##### Sample Output 2:
``````2
1
``````
Console