Please help me correct the loop(line 30) for testcase- Rectangular matrix. The main problem lies with the condition i<n j<m since the loop stops, even if one of them becomes 0 hence leaving either a few rows or columns not updated. Do not suggest me other answers, I have seen them and I know them. I am trying to fix an error here to learn something new. Thanks.
Please help me correct the loop- Prefix Array Sum
hi @rachitbansal2500 refering to : Sum of all the submatrices approach #2 O(n^4) have your doubt got resolved for sum-of-all-submatrices-of-a-given-matrix ??
This doubt is still unresolved
can you tell me the problem statement or title
Sum of all submatrices of a given matrix approach #2
@rachitbansal2500, so you are computing your prefix sum in the original matrix itself (not recommended) the problem with your code is
for( i=1,j=1; (i<n or j<m) ; i++, j++){
what will happen is i and j will both be incremented at the same time thus i and j will have same value
and the loop will only iterate for max(n,m) iteration ,due to which as you said prefix sum matrix will be not updated what you should be doing is to have a nested loop
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
.......
}
}
i have sent you my number you can call me in case of doubt
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.