2970. Count the Number of Incremovable Subarrays I Easy
1/**
2 * [2970] Count the Number of Incremovable Subarrays I
3 *
4 * You are given a 0-indexed array of positive integers nums.
5 * A subarray of nums is called incremovable if nums becomes strictly increasing on removing the subarray. For example, the subarray [3, 4] is an incremovable subarray of [5, 3, 4, 6, 7] because removing this subarray changes the array [5, 3, 4, 6, 7] to [5, 6, 7] which is strictly increasing.
6 * Return the total number of incremovable subarrays of nums.
7 * Note that an empty array is considered strictly increasing.
8 * A subarray is a contiguous non-empty sequence of elements within an array.
9 *
10 * <strong class="example">Example 1:
11 *
12 * Input: nums = [1,2,3,4]
13 * Output: 10
14 * Explanation: The 10 incremovable subarrays are: [1], [2], [3], [4], [1,2], [2,3], [3,4], [1,2,3], [2,3,4], and [1,2,3,4], because on removing any one of these subarrays nums becomes strictly increasing. Note that you cannot select an empty subarray.
15 *
16 * <strong class="example">Example 2:
17 *
18 * Input: nums = [6,5,7,8]
19 * Output: 7
20 * Explanation: The 7 incremovable subarrays are: [5], [6], [5,7], [6,5], [5,7,8], [6,5,7] and [6,5,7,8].
21 * It can be shown that there are only 7 incremovable subarrays in nums.
22 *
23 * <strong class="example">Example 3:
24 *
25 * Input: nums = [8,7,6,6]
26 * Output: 3
27 * Explanation: The 3 incremovable subarrays are: [8,7,6], [7,6,6], and [8,7,6,6]. Note that [8,7] is not an incremovable subarray because after removing [8,7] nums becomes [6,6], which is sorted in ascending order but not strictly increasing.
28 *
29 *
30 * Constraints:
31 *
32 * 1 <= nums.length <= 50
33 * 1 <= nums[i] <= 50
34 *
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/count-the-number-of-incremovable-subarrays-i/
39// discuss: https://leetcode.com/problems/count-the-number-of-incremovable-subarrays-i/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44 pub fn incremovable_subarray_count(nums: Vec<i32>) -> i32 {
45 0
46 }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn test_2970() {
57 }
58}
59
Back
© 2025 bowen.ge All Rights Reserved.