Sum of Array Elements

Given an array of integers, return the sum of all its elements. You must visit every element and accumulate their total in a single forward pass.

Given an array of integers, return the sum of all its elements. You must visit every element and accumulate their total in a single forward pass.

- `1 <= n <= 10^5` - `-10^4 <= arr[i] <= 10^4` - The interactive visualizer accepts 1 to 12 integers; longer valid arrays are execution-only. - The array contains at least one element.

Example 1: input arr = [3, 7, 2, 9, 4]; output 25. Scanning left to right: 3 + 7 + 2 + 9 + 4 = 25.

Example 2: input arr = [-4, 6, -2, 8]; output 8. Negative values are included in the accumulation: -4 + 6 + (-2) + 8 = 8.

Example 3: input arr = [0, 0, 0, 0]; output 0. Each element is zero, so the accumulated total remains 0 throughout.

Category: Arrays. Topic: arrays. Difficulty: Easy. Patterns: linear-scan.