Close
Topic list
Number of Connected Computers.
MEDIUM
10 mins
Matrices (2D Arrays)
Graph
Topics (Covered in this problem)
Problem solved
Skill meter
Matrices (2D Arrays)
-
-
Graph
-
-
Other topics
Problem solved
Skill meter
Strings
-
-
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
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.

# Number of Connected Computers.

Contributed by
Deep Mavani
Medium
0/80
Avg time to solve 10 mins
Success Rate 90 %
Share

## Problem Statement

#### You have been given a grid ‘ARR’ of size ‘N' * M’. ‘ARR[i][j]’ is ‘1’ if the computer is present at position ‘(i,j)’ otherwise it is zero. A computer is said to be a connected computer if there is a computer in its row or column other than itself. Your task is to return the number of connected computers.

##### Example:

``````Let’s say you have a grid [[1,0],[1,1]]. We can say the computer ‘ARR[0][0]’ is a connected computer because there is a computer in its column other than itself. We can say the computer ‘arr[1][0]’ is a connected computer because there is a computer in its row and column other than itself. We can say the computer ‘arr[1][1]’ is a connected computer because there is a computer in its row other than itself. Therefore the number of connected computers is 3.
``````
Detailed explanation ( Input/output format, Notes, Constraints, Images )
##### Sample Input 1:
``````2
4 4
1 1 0 0
0 0 1 0
0 0 0 1
0 0 0 1
2 2
1 0
1 1
``````
##### Sample Output 1:
``````4
3
``````
##### Explanation for Sample Output 1:
``````In test case 1, The computer ‘ARR[0][0]’ is a connected computer because there is a computer in its row other than itself. The computer ‘ARR[0][1]’ is a connected computer because there is a computer in its row other than itself. The computer ‘ARR[1][2]’ is not a connected computer because there is no computer in its row and column other than itself. The computer ‘ARR[3][2]’ is a connected computer because there is a computer in its column other than itself. The computer ‘ARR[3][3]’ is a connected computer because there is a computer in its column other than itself.

In test case 2, The computer ‘ARR[0][0]’ is a connected computer because there is a computer in its column other than itself. The computer ‘ARR[1][0]’ is a connected computer because there is a computer in its row and column other than itself. The computer ‘ARR[1][1]’ is a connected computer because there is a computer in its row other than itself.

``````
##### Sample Input 2:
``````2
2 2
1 0
0 1
2 2
1 1
1 1
``````
##### Sample Output 2:
``````0
4
``````
##### Explanation for Sample Output 2:
``````In test case 1, The computer ‘ARR[0][0]’ is not a connected computer because there is no computer in its row and column other than itself. Also The computer ‘ARR[1][1]’ is not a connected computer because there is no computer in its row and column other than itself.