Skip to content
RED SAGSkills

Minimum Opening Deposit

A wallet starts with an opening deposit D and then applies the balance changes in changes one after another (positive values are credits, negative values are debits).

Return the smallest non-negative integer D such that the balance never drops below 0 at any point.

Example 1

Input: changes = [-3, 5, -4, -2]
Output: 4
Explanation: Running totals are -3, 2, -2, -4. The lowest is -4, so a deposit of 4 is needed.

Example 2

Input: changes = [10, -5, 3]
Output: 0

Constraints

  • 0 <= changes.length <= 10^5
  • -10^4 <= changes[i] <= 10^4
Hint 1

Track the running total and remember the lowest value it reaches.

Hint 2

The deposit must cover the deepest dip, and never needs to be negative.

Good practice for: Frontend Developer, Backend Developer, Full Stack Developer, Mobile App Developer, Automation Test Engineer, Blockchain Developer

Run checks your code on 2 sample tests. Submit runs all 7 tests, including hidden ones, and earns points. Use console.log to debug. Python's first run can take a few seconds while it starts.