Account Balance
Easy · rating 1000 · Arrays, Math
An account starts at 0. The first line contains n, the number of transactions. The second line contains n space-separated signed integers (deposits positive, withdrawals negative). Print the final balance.
Constraints: 1 ≤ n ≤ 105
Editorial
Approach
The balance is the running total of all transactions, and since deposits are positive and withdrawals negative, that is simply their sum.
n = int(input())
print(sum(map(int, input().split())))Complexity
Time: O(n). Space: O(1).
Related problems
- Plus One — Easy
- Class Average — Easy
- Sum of Even Elements — Easy
- Array Sum — Easy
- Shopping Cart Total — Easy
- Missing Number — Medium