Array Sum
Easy · rating 850 · Arrays, Math
The first line contains n. The second line contains n space-separated integers. Print their sum.
Constraints: 1 ≤ n ≤ 105, |ai| ≤ 109
Editorial
Array Sum totals all the integers in a list. Accumulate in a single pass, and keep the total in a 64-bit integer since many large values can overflow 32 bits.
print(sum(nums))Complexity
Time: O(n). Space: O(1).
Related problems
- Shopping Cart Total — Easy
- Alternating Sum — Easy
- Class Average — Easy
- Floor of Average — Easy
- Sum of Even Elements — Easy
- Plus One — Easy