Given a 2D Matrix of dimensions N*N, we need to return sum of all possible submatrices.
[ [1,1], [1,1] ]
Number of submatrices with 1 elements = 4, so sum of all such submatrices = 4*1 = 4 Number of submatrices with 2 elements = 4, so sum of all such submatrices = 4*2 = 8 Number of submatrices with 3 elements = 0 Number of submatrices with 4 elements = 1, so sum of such submatrix = 4 Total Sum = 4+8+4 = 16
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.