I was solving this problem: [2D Array][1]

My approach includes brute-force approach of selecting each element and checking it’s neighbouring elements if they are same or not. But somehow my code is giving wrong answer.

Here’s my code:

```
#include <iostream>
using namespace std;
int main()
{
int a[6][6];
for(int i=0;i<6;i++)
for(int j=0;j<6;j++)
cin>>a[i][j];
int sum,ans=0;
for(int i=1;i<5;i++)
{
for(int j=1;j<5;j++)
{
if(a[i][j] != a[i-1][j] || a[i][j] != a[i][j-1] || a[i][j] != a[i-1][j+1] ||
a[i][j] != a[i+1][j-1] || a[i][j] != a[i+1][j] || a[i][j] != a[i+1][j+1])
sum = a[i][j]+a[i-1][j]+a[i][j-1]+a[i-1][j+1]+a[i+1][j-1]+a[i+1][j]+a[i+1][j+1];
ans = max(sum, ans);
}
}
cout<<ans;
return 0;
}
```

Please Help!

[1]: https://www.hackerrank.com/challenges/2d-array