Sum from 0,0 index to x,j-1 index in prefix sum approach for 2d matrix

the value of q ie x,j-1 will store the sum till x,j-1 starting from 0th index which will even contain value of p so wont it be subtracting the same value twice as the sum will be in rowwise order right

@krishnakumarkrish hi in order to calculate that submatrix sum we have to remove P and Q as this extra part ,only R portion come two times therefore we add one time in final result in order to get result ,the V portion give sum from 0,0 to x,y and P and Q are extra so just remove them and the part which has been removed two times just add once again to final result ,hope you get it :slight_smile:

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.