InterviewBit Academy is now Scaler!
InterviewBit Academy is now Scaler Academy!

Sum of all Submatrices

Given a 2D Matrix of dimensions N*N, we need to return sum of all possible submatrices.

Example Input

[ [1,1],
  [1,1] ]

Example Output



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.
Start solving Sum of all Submatrices on Interview Code Editor
  • Hints are not available for this problem


Click here to start solving coding interview questions