A game gives the player some starting credit, then applies the changes in changes one after another (positive adds credit, negative spends it). The player loses if their credit ever drops below 1.
Write lowestStartingCredit(changes) that returns the smallest positive whole number of starting credit that keeps the credit at 1 or more after every change.
Input: changes = [-2,3,-4,1] Output: 4
The running total dips to -3 after the third change, so the start must be at least 1 - (-3) = 4.
Input: changes = [5,2] Output: 1
The credit only goes up, so the smallest positive start, 1, works.
0 <= changes.length <= 10^5-1000 <= changes[i] <= 1000Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #41 Lowest Starting Credit. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.