GeeksforGeeks Problem of the Day

Raj Gupta18 Jun 2026
#GeeksforGeeks#GFG POTD#GFG Problem of the Day#GeeksforGeeks POTD Solution

It is recommended to first try at your own. 18 June 2026

The GeeksforGeeks POTD solution is given below:

 class Solution {
public:
int findCoverage(vector<vector<int>>& mat) {
// code here
int n=mat.size();
int m=mat[0].size();
int totalCoverage=0;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(mat[i][j]==1) continue;

int top=i-1;
while(top>=0){
if(mat[top][j]==1){
totalCoverage++;
break;
}
top--;
}

int bottom=i+1;
while(bottom<n){
if(mat[bottom][j]==1){
totalCoverage++;
break;
}
bottom++;
}

int right=j+1;
while(right<m){
if(mat[i][right]==1){
totalCoverage++;
break;
}
right++;
}

int left=j-1;
while(left>=0){
if(mat[i][left]==1){
totalCoverage++;
break;
}
left--;
}
}
}
return totalCoverage;
}
};

Written by Raj Gupta