We can represent the sum of any subarray using two prefix sums

  • sum(i to j)=prefixSum[j] - prefixSum[i-1] We can use the idea of a Prefix array to hold these values if we need to store them