Sum Strict Local Maxima
Problem statement
You are given an integer array nums.
An element at index i is a strict local maximum when it has two neighbors and is greater than both of them: nums[i] > nums[i - 1] and nums[i] > nums[i + 1].
Return the sum of all strict local maxima. The first and last elements are never considered because they do not have two neighbors.
Function
sumStrictLocalMaxima(nums: int[]) → longExamples
Example 1
nums = [1,5,2,4,3]return = 95 is greater than 1 and 2, and 4 is greater than 2 and 3. Their sum is 9.
Example 2
nums = [5,1,4]return = 0The only eligible element is 1, which is smaller than both neighbors. The endpoints are not eligible.
Constraints
3 <= nums.length <= 105-109 <= nums[i] <= 109- The answer fits in a signed 64-bit integer.