A game stacks toast notifications in a row, each showing a number in values. You dismiss them one at a time, in any order. Dismissing a toast earns its number times the numbers of its current left and right neighbors. If there is no neighbor on a side, use 1 for that side. After a dismissal, its two neighbors become next to each other.
Write maxDismissPoints(values) that returns the most points you can earn by dismissing every toast.
Input: values = [2,4,3] Output: 33
Dismiss 4 first (2 × 4 × 3 = 24), then 2 (1 × 2 × 3 = 6), then 3 (1 × 3 × 1 = 3).
Input: values = [5] Output: 5
Both neighbors are missing: 1 × 5 × 1.
1 <= values.length <= 3000 <= values[i] <= 100Run 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 #545 Dismiss Toasts for Max Points. 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.