The value of y should be (m-i+1)(n-j+1) instead of (m-i)(n-j) because if we take 3,3 matrix, and take first (0,0) and last (2,2) elements then (2-0)(2-0) would be 2 rows and 2 columns but it is 3*3 matrix
Sum of all Submatrix approach 3
index of bottom-right most cell is n-1 and m-1
for 3X3 matrix
last cell index if 2,2
so contibution of 0,0 (which you want to find)
is x=1;
y=(n-i)(y-j)
y=(3-0)(3-0)=9 which is correct
this is wrong for 3X3 n=3 and m=3
formula is correct as it caculate no of element in a given rectangle
i,j to n-1,m-1
no of element in green region (lower one)= (n-1-i+1)(m-1-j+1)=(n-i)(m-j)
i hope this help
if you have more doubts regarding this feel free to ask
if your doubt is resolved mark it as resolved from your doubt section inside your course
WOW! Thank you so much
1 Like