Count Valleys in a Wiggle Pattern
Problem statement
A valley is an interior index whose value is strictly smaller than both adjacent values.
Return the number of valleys in nums. Endpoints are never valleys, and equal neighbors do not form a strict valley.
Function
countValleys(nums: int[]) → intExamples
Example 1
nums = [5,1,4,2,3]return = 2Indices 1 and 3 are strict valleys.
Example 2
nums = [1,2,3]return = 0The sequence has no valley.
Constraints
0 <= nums.length <= 100000.-10^9 <= nums[i] <= 10^9.
Source note: Author-written prompt excerpt retained for source fidelity.