Count the Number of Incremovable Subarrays I

You are given a 0-indexed array of positive integers nums.

A subarray of nums is called incremovable if nums becomes strictly increasing after removing the subarray.

Return the total number of incremovable subarrays of nums.

Note that an empty array is considered strictly increasing.

A subarray is a contiguous non-empty sequence of elements within an array.

Example 1
Inputnums = [1,2,3,4]
Output10
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 removing any one of these subarrays makes nums strictly increasing.
Example 2
Inputnums = [6,5,7,8]
Output7
There are exactly 7 incremovable subarrays: [5], [6], [5,7], [6,5], [5,7,8], [6,5,7], and [6,5,7,8].

Constraints

  • 1 <= nums.length <= 50
  • 1 <= nums[i] <= 50

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate