#795
Number of Subarrays with Bounded Maximum
specialist · 795 · lc medium +31 · verified · 54.7% accepted · 2,450 likes · top 47%
Description
Given an integer array nums and two integers left and right, return the count of contiguous non-empty subarrays whose maximum element falls within the inclusive range [left, right].
The test cases guarantee the answer fits in a 32-bit integer.
Example 1:
Input: nums = [2,1,4,3], left = 2, right = 3
Output: 3
Explanation: There are three subarrays that meet the requirements: [2], [2, 1], [3].
Example 2:
Input: nums = [2,9,2,5,6], left = 2, right = 8
Output: 7
Code
1
2
3