795. Number of Subarrays with Bounded Maximum Medium

@problem@discussion
#Array#Two Pointers



1/**
2 * [795] Number of Subarrays with Bounded Maximum
3 *
4 * 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].
5 * The test cases are generated so that the answer will fit in a 32-bit integer.
6 *  
7 * Example 1:
8 * 
9 * Input: nums = [2,1,4,3], left = 2, right = 3
10 * Output: 3
11 * Explanation: There are three subarrays that meet the requirements: [2], [2, 1], [3].
12 * 
13 * Example 2:
14 * 
15 * Input: nums = [2,9,2,5,6], left = 2, right = 8
16 * Output: 7
17 * 
18 *  
19 * Constraints:
20 * 
21 * 	1 <= nums.length <= 10^5
22 * 	0 <= nums[i] <= 10^9
23 * 	0 <= left <= right <= 10^9
24 * 
25 */
26pub struct Solution {}
27
28// problem: https://leetcode.com/problems/number-of-subarrays-with-bounded-maximum/
29// discuss: https://leetcode.com/problems/number-of-subarrays-with-bounded-maximum/discuss/?currentPage=1&orderBy=most_votes&query=
30
31// submission codes start here
32
33impl Solution {
34    pub fn num_subarray_bounded_max(nums: Vec<i32>, left: i32, right: i32) -> i32 {
35        0
36    }
37}
38
39// submission codes end
40
41#[cfg(test)]
42mod tests {
43    use super::*;
44
45    #[test]
46    fn test_795() {
47    }
48}
49


Back
© 2025 bowen.ge All Rights Reserved.