A revenue chart should shade the stretch of back-to-back days with the largest total change in gains.
Write bestStreakRange(gains) that returns [start, end], the first and last index of that stretch (at least one day). If several stretches share the largest total, return the one that starts earliest; if they also start on the same day, return the shortest.
Input: gains = [2,-5,3,-1,4,-6,2] Output: [2,4]
3 - 1 + 4 = 6 is the largest total.
Input: gains = [1,-1,1] Output: [0,0]
[0, 0], [2, 2], and [0, 2] all total 1. The earliest start is 0, and the shortest from there is [0, 0].
1 <= gains.length <= 2 * 10^5-10^4 <= gains[i] <= 10^4Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #64 Locate the Best Streak. 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.