Find Maximum Calories
Problem statement
You start on the ground at height 0. There are n stones, and stone i has height height[i].
You must visit every stone exactly once, in any order. After jumping from the ground to the first stone, you cannot return to the ground. A jump between heights x and y burns (x - y)² calories.
Return the maximum total calories that can be burned.
Function
findMaximumCalories(height: int[]) → longExamples
Example 1
height = [5, 2, 5]return = 43Use the order ground 0 → third stone 5 → second stone 2 → first stone 5. The total is (0 - 5)² + (5 - 2)² + (2 - 5)² = 25 + 9 + 9 = 43, which is optimal.
Constraints
1 ≤ n ≤ 10^5height.length = n1 ≤ height[i] ≤ 46340