Problem · Stack
Count Bowl Subarrays
Learn this problemProblem statement
You are given an integer array nums with distinct elements.
A subarray nums[l...r] is a bowl when:
- Its length is at least
3. - The smaller of its two endpoint values is strictly greater than every value between the endpoints.
Return the number of bowl subarrays.
Function
bowlSubarrays(nums: int[]) → longExamples
Example 1
nums = [2,5,3,1,4]return = 2The bowl subarrays are [3,1,4] and [5,3,1,4].
Example 2
nums = [5,1,2,3,4]return = 3The valid bowl subarrays are [5,1,2], [5,1,2,3], and [5,1,2,3,4].
Constraints
3 <= nums.length <= 10^51 <= nums[i] <= 10^9numscontains distinct values.