---
# System prepended metadata

title: 0303. Range Sum Query - Immutable
tags: [Leetcode, FaceBook, Easy, Prefix Sum]

---

# 0303. Range Sum Query - Immutable
###### tags: `Leetcode` `Easy` `FaceBook` `Prefix Sum`
Link: https://leetcode.com/problems/range-sum-query-immutable/
## Code
```java=
class NumArray {
    int[] prefixSum;
    
    public NumArray(int[] nums) {
        prefixSum = new int[nums.length+1];
        for(int i = 1;i < prefixSum.length;i++){
            prefixSum[i] = prefixSum[i-1]+nums[i-1];
        }
    }
    
    public int sumRange(int left, int right) {
        return prefixSum[right+1]-prefixSum[left];
    }
}


```