What is problem in this sbumatrix approach 2;

There will be three corner cases for prefix sum from (li,lj) to (bi,bj).

                 if(li==0 && lj==0){
                    sum=sum+a[bi][bj];
                }
                else if(li==0){
                    sum = a[bi][bj]-a[bi][lj-1];
                }
                else if(lj==0){
                    sum = a[bi][bj]-a[li-1][bj];
                }
                else{
                    sum = a[bi][bj]-a[bi][lj-1]-a[li-1][bj]+a[li-1][lj-1];
                }

You can easily understand these by just drawing them for some matrix example.

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.