A carousel shows reward cards in a row, worth points[i] each. A player may take exactly k cards, but each card must be taken from the left end or the right end of what's left of the row.
Write bestPicks(points, k) that returns the largest total the player can collect. k is never more than the number of cards.
Input: points = [1,2,3,4,5,6,1], k = 3 Output: 12
Take the three cards on the right: 1 + 6 + 5 = 12.
Input: points = [9,7,7,9,7,7,9], k = 7 Output: 55
Taking every card gives the total, 55.
1 <= k <= points.length <= 1000001 <= points[i] <= 10^4Run 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 #131 Best Picks from Both Ends. 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.