2444. Count Subarrays With Fixed Bounds

Updated: 2024-03-31
1 min read
[]

On This Page

LeetCode problem 2444

class Solution:
    def countSubarrays(self, nums: List[int], minK: int, maxK: int) -> int:
        j1 = j2 = k = -1
        res = 0
        for i, v in enumerate(nums):
            if v < minK or v > maxK:
                k = i
            if v == minK:
                j1 = i
            if v == maxK:
                j2 = i
            res += max(0, min(j1, j2) - k)
        return res