some cases index goes to -1 so how can i handle this condtion
for example top pointer 0,0 and botton pointer 1,1 then we also calculate pre[-1][-1], pre[1][-1]
and pre[-1][1] such invalide index
$ Sum Of All Submatrix From A given Matrix - Approach 2
Hello @khemchandrs,
Solution:
Add some conditional checks to your code to avoid such cases:
The junk values are getting added and subtracted from the sum for the cases:
- When li=0
- when lj=0
You have to check for these cases before computing the sum.
Refer to the following code to better understand what i am saying:
Hope, this would help.
Give a like if you are satisfied.
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.