Ctrl K

Balance After Each Day

Easy
An account is opened with a zero balance. The array changes records how much the balance moved on each day: a positive number is a deposit, a negative one is a withdrawal. Return an array of the same length whose i-th element is the balance at the end of day i, that is, changes[0] + changes[1] + … + changes[i].
Example 1
changes=[500, -200, 300, -1000] → [500, 300, 600, -400]

The balance after each day: 500, 500 − 200 = 300, 300 + 300 = 600, 600 − 1000 = −400.

Example 2
changes=[0, 0, 7] → [0, 0, 7]

Two quiet days, then 7 comes in on the third.

Example 3
changes=[-3] → [-3]

With a single day the answer is just that change.

Constraints
  • 1 ≤ changes.length ≤ 10^5
  • -10^6 ≤ changes[i] ≤ 10^6
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsBalance Point Index EasyThe Battery Must Not Run Dry EasyTotals of Odd-Length Slices EasyThe Hiker's Highest Point EasyThe Busiest Year Easy
loading Python…
Input
changes=[500, -200, 300, -1000]
Expected
[500, 300, 600, -400]

Run checks the first 3 tests in your browser. Submit checks all 91 tests on the server, hidden ones included.