I think there are 4 Problems in the code discussed in the video

  1. In int main(), while taking input, i should have limits from 0 to m and not from 0 to n.
  2. In maxSumSubmatrix(), in col wise addition i should be from m-1 to 0 and j should be from n-2 to 0.
  3. Similarly, for row-wise addition, i should be n-1 to 0 and j should be from m-2 to 0.
  4. While iterating over the array to find max element, i should be from 0 to m and not from 0 to n.

hello @sahilkhan2312000131
pls share the code that u r referring , i will check and let u know about the mistakes.

#include<bits/stdc++.h>
using namespace std;

int maxSumSubmatrix(int **arr, int n, int m){

//col wise addition first

for(int i=n-1;i>=0;i–){
for(int j=m-2;j>=0;j–){
arr[i][j]+=arr[i][j+1];
}
}

// row wise addition secondly
for(int i=m-1;i>=0;i–){
for(int j=n-2;j>=0;j–){
arr[j][i]+=arr[j+1][i];
}
}

int result=INT_MIN;

for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
result=max(result,arr[i][j]);
}
}
return result;

}

int main(int argc, char const *argv[]){
int n,m;
cin>>n>>m;
int *arr=new int[n];

for(int i=0;i<n;i++){
arr[i]=new int [m];
}

for(int i=0;i<n;i++){
for(int j=0;i<n;j++){
cin>>arr[i][j];
}
}

cout<<maxSumSubmatrix(arr,n,m)<<endl;
return 0;

}

I think these changes should be made:

  1. In int main(), while taking input, i should have limits from 0 to m and not from 0 to n.
  2. In maxSumSubmatrix(), in col wise addition i should be from m-1 to 0 and j should be from n-2 to 0.
  3. Similarly, for row-wise addition, i should be n-1 to 0 and j should be from m-2 to 0.
  4. While iterating over the array to find max element, i should be from 0 to m and not from 0 to n.

@sahilkhan2312000131
yeah check if n is for rows and m is for col then whatever u r saying is correct.