Shopping Cart Total
Easy · rating 850 · Arrays, Math
A shopping cart holds n items. The first line contains n. The second line contains n item prices in cents. Print the total price of the cart in cents.
Constraints: 1 ≤ n ≤ 105
Editorial
Shopping Cart Total sums item prices given in cents. Accumulate in one pass and keep the total in a 64-bit integer. Working in integer cents rather than floating-point dollars avoids rounding errors.
print(sum(prices))Complexity
Time: O(n). Space: O(1).
Related problems
- Array Sum — Easy
- Alternating Sum — Easy
- Class Average — Easy
- Floor of Average — Easy
- Sum of Even Elements — Easy
- Plus One — Easy