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).