A cloud billing page tracks cost changes per minute in changes; a change can be negative when a credit is applied. An alert fires on the shortest burst of consecutive minutes whose changes add up to at least budget.
Write shortestBurst(changes, budget) that returns the length of the shortest non-empty run of consecutive minutes with a sum of at least budget, or -1 if no run reaches it.
Input: changes = [2,-1,2], budget = 3 Output: 3
Only the whole run 2 - 1 + 2 = 3 reaches 3.
Input: changes = [1,2], budget = 4 Output: -1
The total is only 3.
1 <= changes.length <= 10^5-10^5 <= changes[i] <= 10^51 <= budget <= 10^9Run 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 #274 Shortest Burst Over Budget. 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.