how to make prefix sum of 2d array ? for this problem?
Prefix sum 2d array
for generating prefix sum submatrix
first you have to sum column wise and then row wise
use this
for(int i=0;i<n;i++){
for(int j=1;j<n;j++){
arr[i][j]+=arr[i][j-1];
}
}
for(int j=0;j<n;j++){
for(int i=1;i<n;i++){
arr[i][j]+=arr[i-1][j];
}
}
now in the array arr[i][j] represent the sum of submatrix starting form (0,0) to (i,j)
i hope this helps
if yes hit a like and don’t forgot to mark doubt as resolved
if you have more doubts regarding this feel free to ask
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.