Im getting wrong output for 1st approach for sum of all submatrix of a given matrix
@kishoretaru
your loops were wrong. the correct sequence.
coordinates of rectangle are (l,b) [top left corner] and (k,t) [bottom right corner].
for (int l = 0; l < n; l++) {
for (int b = 0; b < m; b++) {
for (int k = l; k < n; k++) {
for (int t = b; t < m; t++) {
for (int i = l; i <= k; i++) {
for (int j = b; j <= t; j++) {
sum += a[i][j];
}
}
}
}
}
}
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.