137. Number of Subarrays with Bounded Maximum

HardArrayArray

Given an integer array nums and two integers left and right, return the number of contiguous non-empty subarrays whose maximum element is in the range [left, right]. Input: '[nums], left, right'.

Input: '[nums], left, right'.

Output: Integer — count of subarrays.

Examples

Example 1
Input: [2,1,4,3], 2, 3
Output: 3
Explanation: Subarrays [2],[2,1],[3].
Example 2
Input: [2,9,2,5,6], 2, 8
Output: 7
Explanation: Seven valid subarrays.

Constraints

Asked by

AdobeAmazonGoogle
Solve this problem in the editor →