Count Subarrays With Fixed Bounds solution leetcode

Count Subarrays With Fixed Bounds solution leetcode

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

fixed-bound subarray of nums is a subarray that satisfies the following conditions:

  • The minimum value in the subarray is equal to minK.
  • The maximum value in the subarray is equal to maxK.

Count Subarrays With Fixed Bounds solution leetcode

Return the number of fixed-bound subarrays.

subarray is a contiguous part of an array.

 

Count Subarrays With Fixed Bounds solution leetcode

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.

Count Subarrays With Fixed Bounds solution leetcode

Constraints:

  • 2 <= nums.length <= 105
  • 1 <= nums[i], minK, maxK <= 106

Leave a Comment