Answering many "sum from index l to r" questions by looping each time is O(n) per query and too slow when there are thousands of queries. A prefix sum array stores running totals once, after which any range sum is one subtraction. Reach for it when the array does not change and you get many range sum queries, or when counting subarrays with a given sum. If the values keep changing between queries, prefix sums go stale and need rebuilding.