Q: Given an N-array of immutable ints, write an efficient sumMatrixSum(le,ri,top,bot). Assume top-most and left-most indices are zeros.
My solution: pre-populate in O(NN) a shadow-matrix s, where at each location s(row, col) is the sum of submatrix(0,col, 0, bot).
Query will be O(1) :
s(0,ri, bot) + s(le-1, top-1) – s(le-1, bot) – s(r, top-1)