2444. Count Subarrays With Fixed Bounds Hard
1/**
2 * [2444] Count Subarrays With Fixed Bounds
3 *
4 * You are given an integer array nums and two integers minK and maxK.
5 * A fixed-bound subarray of nums is a subarray that satisfies the following conditions:
6 *
7 * The minimum value in the subarray is equal to minK.
8 * The maximum value in the subarray is equal to maxK.
9 *
10 * Return the number of fixed-bound subarrays.
11 * A subarray is a contiguous part of an array.
12 *
13 * Example 1:
14 *
15 * Input: nums = [1,3,5,2,7,5], minK = 1, maxK = 5
16 * Output: 2
17 * Explanation: The fixed-bound subarrays are [1,3,5] and [1,3,5,2].
18 *
19 * Example 2:
20 *
21 * Input: nums = [1,1,1,1], minK = 1, maxK = 1
22 * Output: 10
23 * Explanation: Every subarray of nums is a fixed-bound subarray. There are 10 possible subarrays.
24 *
25 *
26 * Constraints:
27 *
28 * 2 <= nums.length <= 10^5
29 * 1 <= nums[i], minK, maxK <= 10^6
30 *
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/count-subarrays-with-fixed-bounds/
35// discuss: https://leetcode.com/problems/count-subarrays-with-fixed-bounds/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40 pub fn count_subarrays(nums: Vec<i32>, min_k: i32, max_k: i32) -> i64 {
41
42 }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn test_2444() {
53 }
54}
55
Back
© 2025 bowen.ge All Rights Reserved.