Practice Number of Subarrays with Bounded Maximum
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Given an integer array nums and two integers left and right, return the number of contiguous non-empty subarrays such that the value of the maximum array element in that subarray is in the range [left, right]. The test cases are generated so that the answer will fit in a 32-bit integer.
Source: Number of Subarrays with Bounded Maximum on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
nums = [2,1,4,3], left = 2, right = 3
Output
3
# Example 2
Input
nums = [2,9,2,5,6], left = 2, right = 8
Output
7
Constraints
1 <= nums.length <= 10^5
0 <= nums[i] <= 10^9
0 <= left <= right <= 10^9
Related LeetCode Problems
Practice more problems similar to Number of Subarrays with Bounded Maximum.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.