#2444

Count Subarrays With Fixed Bounds

expert · 1005 · lc hard +32 · verified · 69.2% accepted · 3,760 likes · top 77%

Description

You are given an integer array nums and two integers minK and maxK.

A fixed-bound subarray of nums satisfies:

- Its minimum element equals minK.

- Its maximum element equals maxK.

Count and return the number of fixed-bound subarrays.

Example 1:

Input: nums = [1,3,5,2,7,5], minK = 1, maxK = 5
Output: 2
Explanation: The fixed-bound subarrays are [1,3,5] and [1,3,5,2].

Example 2:

Input: nums = [1,1,1,1], minK = 1, maxK = 1
Output: 10
Explanation: Every subarray of nums is a fixed-bound subarray. There are 10 possible subarrays.

Code

1
2
3