Fixing columns is not working


#1

why does fixing columns instead of rows doesn’t work? it gives runtime error, whereas on leetcode it gets submitted


#2

Fixing columns is working properly.
Don’t forget to check if your matrix is initially empty or not.

My code:

int kadane(vectorarr,int n){
int sum=0,cnt=0;
map<int,int>mp;
for(int i=0;i<n;i++){
sum+=arr[i];
if(sum==0) cnt++;
if(mp.find(sum)!=mp.end()) cnt+=mp[sum];
mp[sum]++;
}
return cnt;
}

int Solution::solve(vector<vector > &arr) {
if(arr.empty()) return 0;
int m=arr.size(),n=arr[0].size();
int cnt=0;
for(int c1=0;c1<n;c1++){
vectorrow(m);
for(int c2=c1;c2<n;c2++){
for(int i=0;i<m;i++) row[i]+=arr[i][c2];
cnt+=kadane(row,m);
}
}
return cnt;
}


#3

thanks alot…it saved my time for mentioning the condition to check whether matrix is empty or not