3113. Find the Number of Subarrays Where Boundary Elements Are Maximum
3113. Find the Number of Subarrays Where Boundary Elements Are Maximum
Description
You are given an array of positive integers nums
.
Return the number of subarrays of nums
, where the first and the last elements of the subarray are equal to the largest element in the subarray.
Example 1:
1 | Input: nums = [1,4,3,3,2] |
Example 2:
1 | Input: nums = [3,3,3] |
Example 3:
1 | Input: nums = [1] |
Constraints:
1 <= nums.length <= 10^5
1 <= nums[i] <= 10^9
Hints/Notes
- monotonic stack/max stack
Solution
Language: C++
1 | class Solution { |