3676. Count Bowl Subarrays Medium
1/**
2 * [3676] Count Bowl Subarrays
3 *
4 * You are given an integer array nums with distinct elements.
5 * A <span data-keyword="subarray">subarray</span> nums[l...r] of nums is called a bowl if:
6 *
7 * The subarray has length at least 3. That is, r - l + 1 >= 3.
8 * The minimum of its two ends is strictly greater than the maximum of all elements in between. That is, min(nums[l], nums[r]) > max(nums[l + 1], ..., nums[r - 1]).
9 *
10 * Return the number of bowl subarrays in nums.
11 *
12 * <strong class="example">Example 1:
13 * <div class="example-block">
14 * Input: <span class="example-io">nums = [2,5,3,1,4]</span>
15 * Output: <span class="example-io">2</span>
16 * Explanation:
17 * The bowl subarrays are [3, 1, 4] and [5, 3, 1, 4].
18 *
19 * [3, 1, 4] is a bowl because min(3, 4) = 3 > max(1) = 1.
20 * [5, 3, 1, 4] is a bowl because min(5, 4) = 4 > max(3, 1) = 3.
21 * </div>
22 * <strong class="example">Example 2:
23 * <div class="example-block">
24 * Input: <span class="example-io">nums = [5,1,2,3,4]</span>
25 * Output: <span class="example-io">3</span>
26 * Explanation:
27 * The bowl subarrays are [5, 1, 2], [5, 1, 2, 3] and [5, 1, 2, 3, 4].
28 * </div>
29 * <strong class="example">Example 3:
30 * <div class="example-block">
31 * Input: <span class="example-io">nums = </span>[1000000000,999999999,999999998]
32 * Output: <span class="example-io">0</span>
33 * Explanation:
34 * No subarray is a bowl.
35 * </div>
36 *
37 * Constraints:
38 *
39 * 3 <= nums.length <= 10^5
40 * 1 <= nums[i] <= 10^9
41 * nums consists of distinct elements.
42 *
43 */
44pub struct Solution {}
45
46// problem: https://leetcode.com/problems/count-bowl-subarrays/
47// discuss: https://leetcode.com/problems/count-bowl-subarrays/discuss/?currentPage=1&orderBy=most_votes&query=
48
49// submission codes start here
50
51impl Solution {
52 pub fn bowl_subarrays(nums: Vec<i32>) -> i64 {
53
54 }
55}
56
57// submission codes end
58
59#[cfg(test)]
60mod tests {
61 use super::*;
62
63 #[test]
64 fn test_3676() {
65 }
66}
67Back
© 2026 bowen.ge All Rights Reserved.