#3676
Count Bowl Subarrays
medium · 48% accepted · 183 likes · top 33%
array · stack · monotonic stack
Description
You are given an integer array nums with distinct elements.
A subarray nums[l...r] of nums is called a bowl if:
- The subarray has length at least 3. That is, r - l + 1 >= 3.
- The minimum of its two ends is strictly greater than the maximum of all elements in between. That is, min(nums[l], nums[r]) > max(nums[l + 1], ..., nums[r - 1]).
Return the number of bowl subarrays in nums.
Solution