An animation editor samples an easing curve that overshoots: the sampled values in values rise strictly to a single highest point and then fall strictly. Either part may be empty, so the peak can be the first or last sample.
Write peakFrame(values) that returns the index of the highest sample. Use O(log n) comparisons; ternary search is a natural fit.
Input: values = [1,3,8,12,15,11,6,2] Output: 4
The values climb to 15 at index 4, then fall.
Input: values = [9,7,4,1] Output: 0
The curve only falls, so the first sample is the peak.
1 <= values.length <= 100000-10^6 <= values[i] <= 10^6Run 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 #177 Peak of an Easing Curve. 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.