Here is how we will solve it, first of all we need a helping array of already calculated sums, let's call it sum where sum[i][j] shows the sum of elements of the i-th row from 1 to j. Now we will fix some interval from 1 to N for the columns, and another interval from 1 to N to all the rows. In other words, if we have an interval of [C1,C2] for columns and [R1,R2] for rows then we need to calculate the sum of a square which has top left coordinates of [R1,C1] and bottom right coordinates [R2,C2]. In the process update the value of the final answer if necessary.
No comments:
Post a Comment