A music app plays a playlist on repeat. Each song has a rating change in ratings (positive is liked, negative skipped). Because the playlist loops, a segment can run off the end and continue from the start, but it can't include any song twice.
Write bestLoopSegment(ratings) that returns the largest total of a segment of at least one song.
Input: ratings = [4,-6,3,-1,5] Output: 11
The segment 3, -1, 5, wrapping to 4, totals 11.
Input: ratings = [-3,-2,-5] Output: -2
Every song is negative, so pick the single best one.
1 <= ratings.length <= 10^5-2 * 10^4 <= ratings[i] <= 2 * 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 #63 Circular Playlist Best Segment. 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.