Easy C++ Solve on copy pen to understand this code


#1

int Solution::solve(vector<vector > &A, int B) {
int sum =0;
int temp=0;
int ans =INT_MIN;

while(temp+B<=A.size()){
    for(int i=0;i<B;i++)
        for(int j=temp;j<B+temp;j++)
            sum+=A[j][i];
            
    ans = max(ans,sum);
    
    for(int i=B;i<A[0].size();i++){
        for(int j=temp;j<B+temp;j++){
            sum+=A[j][i];
            sum-=A[j][i-B];
        }
    ans = max(ans,sum);
}
sum=0;
temp++;
}
return ans;

}