class Solution { public: int findCoverage(vector& matrix) { // Code here int ans = 0; int n = matrix.size(); int m = matrix[0].size(); for(int i = 0; i < n; i++){ for(int j = 0; j < m-1; j++){ ans+=matrix[i][j]^matrix[i][j+1]; } } for(int i = 0; i < m; i++){ for(int j = 0; j < n-1; j++){ ans+=matrix[j][i]^matrix[j+1][i]; } } return ans; } }; I have tried this approach and works correctly. Just basic XOR operation.
int covverage(vector &matrix) { int r = matrix.size(); int c = matrix[0].size(); int sum = 0; for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { if (matrix[i][j] == 0) { if (j > 0 && matrix[i][j - 1] == 1) // left element { sum += 1; } if (i < r - 1 && matrix[i][j + 1] == 1) //right element { sum += 1; } if (i > 0 && matrix[i - 1][j] == 1) // upside element { sum += 1; } if (i < r - 1 && matrix[i + 1][j] == 1) // downside element { sum += 1; } } } return sum; } } bhai ye code chal to gaya but muje right side element and downside element mai i < r - 1 , j < c - 1 ye boundary cases ka logic samaj nahi aya can you help in this
Nice 👍
Thanks 😊
Very helpful video! The explanation is clear and easy to understand. Great job!
Thanks 😊
Bro teri level of understanding bohot acchi hai how you achieve this level of knowledge are you iitian of what
Thanks bro...no I'm not iitian
All this can be achieved by regular practice 😊
Thanks for sharing explanation bro 💜
Welcome bro 😊
class Solution {
public:
int findCoverage(vector& matrix) {
// Code here
int ans = 0;
int n = matrix.size();
int m = matrix[0].size();
for(int i = 0; i < n; i++){
for(int j = 0; j < m-1; j++){
ans+=matrix[i][j]^matrix[i][j+1];
}
}
for(int i = 0; i < m; i++){
for(int j = 0; j < n-1; j++){
ans+=matrix[j][i]^matrix[j+1][i];
}
}
return ans;
}
};
I have tried this approach and works correctly. Just basic XOR operation.
Awsm👏🏻
@@CodeGenius316 Thanks😃
int covverage(vector &matrix)
{
int r = matrix.size();
int c = matrix[0].size();
int sum = 0;
for (int i = 0; i < r; i++)
{
for (int j = 0; j < c; j++)
{
if (matrix[i][j] == 0)
{
if (j > 0 && matrix[i][j - 1] == 1) // left element
{
sum += 1;
}
if (i < r - 1 && matrix[i][j + 1] == 1) //right element
{
sum += 1;
}
if (i > 0 && matrix[i - 1][j] == 1) // upside element
{
sum += 1;
}
if (i < r - 1 && matrix[i + 1][j] == 1) // downside element
{
sum += 1;
}
}
}
return sum;
}
} bhai ye code chal to gaya but muje right side element and downside element mai i < r - 1 , j < c - 1 ye boundary cases ka logic samaj nahi aya can you help in this
Bhai ye code same mere Wale jaisa hai...video dekho yehi cheez smjha rkhi hai maine