While explaining in video bhaiya took an example of 1d array which was [1 2 3 4 5]. He used to add every element and update it then the result was [1,3 6,10, 15]. So I think that result was 15 . But he then subtracts (15-3+2) so result was 14.
I want to ask why we have done subtraction?
Even the sum is 15 but he told sum was 14 how??
And from where 3 and 2 came?
Sum of All submatrix Approach-2
Watch at point 3:00 in video of sum of all submatrix Approach -2
@ashwani225
So the point was we need sum of elements from index 1 to 4
So we made prefix sum array
Then we did pre_sum[4] - pre_sum[1] + arr[1]
pre_sum[4] = 15
pre_sum[1] = 3
arr[1] = 2
So val is 14 which is sum of elements from index 1 to 4
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.