Close
Topic list
Special Cells in Binary Matrix
EASY
30 mins
Matrices (2D Arrays)
Topics (Covered in this problem)
Problem solved
Skill meter
Matrices (2D Arrays)
-
-
Other topics
Problem solved
Skill meter
Strings
-
-
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

# Special Cells in Binary Matrix

Contributed by
srejanbera
Easy
0/40
Avg time to solve 30 mins
Success Rate 75 %
Share

## 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).
``````
Detailed explanation ( Input/output format, Notes, Constraints, Images )
##### 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
``````
Auto
Console