303. Range Sum Query - Immutable
Approach 1: Pre-sum/ Cumulative PreSum
When we initialize the NumArray we can keep track of the sums of each of the positions, and eventually when sumRange is called we can just subtract the sums between position j and position i
Time Complexity: O(N) [init method] O(1) [sumRange]
Space Complexity: O(N)
Last updated