Doubt with the approach taught in the video

For finding the bottom right corner, the loop started from i+1 and j+1 respectively, how does this include all the 1 X 1 matrices. Shouldn’t the loop for bottom right start from i & j only

Hey @chaturvedia336,
Yes it will consitute all the 1X1 matrix as well cosider i =0 , j =0 , Then top left will be (0,0) and the bottom right will be (1,1) .

Now the sum loop looks like

for(int i=li ; i<bi ; i++){
for(int j=lj ; j<bj ; j++){
sum += arr[i][j];
}
}

Now , if you see for top left(0,0) and bottom right(1,1) .
the loop is considering (0,0) which is what we want.You can dry run for more rectangles as well it will give you a clearer idea .

Hope it helps :blush: .
If your doubt is now resolved please mark it as resolved and rate me accordingly .
Else you can further questions here .
Thankyou